27
2017
09

jenkins服务器的搭建和配置

curl -O https://pkg.jenkins.io/debian/jenkins-ci.org.key
apt-key add jenkins-ci.org.key
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins


sudo apt-get install software-properties-common
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

启动
sudo /etc/init.d/jenkins start
停止
sudo /etc/init.d/jenkins stop
配置文件
/etc/default/jenkins

sudo aptitude -y install nginx
cd /etc/nginx/sites-available
sudo rm default ../sites-enabled/default

/etc/nginx/sites-available/jenkins文件

server {
    listen 80;
    listen [::]:80 default ipv6only=on;
    server_name 116.62.163.50;

    root /home/;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;

        if (!-f $request_filename) {
            proxy_pass http://localhost:8080;
            break;
        }
    }

    location /jenkins-result {
        autoindex on;
    }
}

sudo ln -s /etc/nginx/sites-available/jenkins /etc/nginx/sites-enabled/
sudo service nginx restart

访问xxx.xxx.xxx.xxx
解锁jenkins

cat /var/lib/jenkins/secrets/initialAdminPassword
github的配置

https://github.com/settings/tokens 
1.Generate new token
2.repo
  admin:repo_hook
3.保存生成的token

进入GitHub的工程 --> setting --> WebHooks&Services --> add webhook --> 输入jenkins的地址

系统管理 --> 系统设置 --> GitHub --> Add GitHub Sever
1. API URL: https://api.github.com,
2. Credentials点击Add添加,Kind选择Secret Text, Secret填github生成的access_token

点击TestConnection, 提示Credentials verified for user UUserName, rate limit: xxx, 则设置成功
add Credential
使用Username with password类型
填入github帐号和密码
配置jenkins自己的邮件地址

"Manage Jenkins" -> "Configure System" -> "Extended E-mail Notification"

SMTP server 
高级-> Use SMTP Authentication-> User Name 
                                Password
                                Use SSL
                                SMTP port
github添加服务器的公钥

(jenkins-server)ssh-keygen
(jenkins-server)cat ~/.ssh/id_rsa.pub
(github)Settings->SSH and GPG keys->New SSH key

测试: ssh -T git@github.com

修改jenkins的运行权限
gpasswd -a root jenkins

/etc/default/jenkins

JENKINS_USER=root  
JENKINS_GROUP=root

sudo service jenkins restart


export GRADLE_HOME=xxx/gradle-4.2/bin
export ANDROID_HOME=xxx/android-sdk

$GRADLE_HOME/gradle clean 

$GRADLE_HOME/gradle :app:assemble${CHANNEL} -PWORKSPACE=${WORKSPACE} -PJOB_NAME=${JOB_NAME} -PBUILD_NUMBER=${BUILD_NUMBER} -PRESULT_LOCAL_DIR="xxx" -PBRANCH=${BRANCH} -PRESULT_URL="xxx"


android sdk
curl -O https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip
unzip sdk-tools-linux-3859397.zip -d ~/workspace/
ANDROID_HOME/bin/sdkmanager --list
ANDROID_HOME/bin/sdkmanager --sdk_root=ANDROID_HOME "build-tools;26.0.1" "platform-tools" "tools" "platforms;android-24" "ndk-bundle" "extras;android;m2repository" "extras;google;m2repository"
ANDROID_HOME/bin/sdkmanager --licenses

gradle
curl -O https://downloads.gradle.org/distributions/gradle-4.2-bin.zip
unzip gradle-4.2-bin.zip -d ~/workspace/

上一篇:Android设置ListView的分割线长度 下一篇:数据库加密之iOS项目配置SQLCipher