引言
- 啥是jenkins?jenkins是一个基于java的可扩展的持续集成( CI)的引擎,持续、自动的构建软件。
- 啥是持续集成?频繁的将修改的代码集成到主分支上。
- 有啥好处?解决重复劳动,快速试错。
- 如何实现?通过一个可获取源码的仓库,通过预先设定好的脚本执行操作。
环境配置
安装jdk
mkdir /usr/java
cd /usr/java
yum search java|grep jdk
yum install java-1.8.0-openjdk.x86_64
//error bad ELF interpreter
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7u71-b14/jdk-7u71-linux-x64.rpm
rpm -ivh jdk-8u144-linux-i586.rpm
//error:open of <html> failed: No such file or directory
wget http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-i586.rpm
//最新JDK版本http://www.oracle.com/technetwork/java/javase/downloads/index.html
rpm -ivh jdk-8u144-linux-i586.rpm
安装Android-SDK
//下载
wget https://dl.google.com/android/android-sdk_r24.2-linux.tgz
//解压
tar xvzf android-sdk_r24.2-linux.tgz
//设置ANDROID_HOME
mv android-sdk-linux /usr/local/Android-SDK
//安装所有包
android update sdk --no-ui
安装gradle
//下载
cd /usr/local
wget https://services.gradle.org/distributions/gradle-3.3-all.zip
//解压、安装
unzip gradle-3.3-all.zip
mv gradle-3.3 /usr/local/gradle
//配置1
echo 'export GRADLE_HOME=/usr/local/gradle' > /etc/profile.d/gradle.sh
echo 'export PATH=$PATH:$GRADLE_HOME/bin' >> /etc/profile.d/gradle.sh
. /etc/profile.d/gradle.sh
//配置2
vi /etc/profile
GRADLE_HOME=/usr/local/gradle
export PATH=${GRADLE_HOME}/bin:${PATH}
//error:You have not accepted the license agreements of the following SDK components:
mkdir "$ANDROID_HOME/licenses"
echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
安装jenkins
//添加源
sudo wget -O /etc/yum.repos.d/jenkins.repo http://jenkins-ci.org/redhat/jenkins.repo
sudo rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
//安装
sudo yum -y install jenkins
//运行
sudo service jenkins start
这个时候就可以通过8080端口访问jenkinx了。
处理nginx冲突
若你的服务器上用nginx代理了服务器,则需对nginx进行配置,否则无法通过8080端口打开jenkins。生成conf文件
server {
listen 80;
server_name www.xx.com xx.com;
#access_log /var/log/jenkins_access_log main; #error_log /var/log/jenkins_error_log debug_http;
client_max_body_size 60M;
client_body_buffer_size 512k;
location / {
proxy_pass http://localhost:8080/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
service nginx restart
配置jenkins
项目配置
- GitHub project->Project url
- 源码管理->GIT Repository URLz、Credentials
- Branches to build
- 源码库浏览器->githubweb、url
- 构建触发器->GitHub hook trigger for GITScm polling
- 构建->execute shell->command
- 构建后操作->Editable Email Notification
全局配置
- 全局属性->Environment variables->key:ANDROID_HOME value:/usr/local/Android-SDK
网友评论