From: chengli3 Date: Mon, 9 Sep 2019 02:17:14 +0000 (+0800) Subject: Add the script for Jenkins setup X-Git-Tag: v0.4.0~85 X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=commitdiff_plain;h=0e03f090b02ca0ee5f2d85d1e7b32f40ef4e10c7;p=icn.git Add the script for Jenkins setup This patch is to add the script/ansible_playbook for Jenkins setup: 1. Setup jenkins server by leverage jenkins role from galaxy 2. Add akraino gerrit server to gerrit list 3. Add pipeline job for ICN CI check Change-Id: I2baf2a35ba246faab8a7be599af7bd5b2123dd79 --- diff --git a/Jenkinsfile b/Jenkinsfile index b7b5c7f..895065a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,8 +9,22 @@ pipeline { stages { stage("Build ISO Image") { steps { - echo "refspec: ${GERRIT_REFSPEC}, branch: ${GERRIT_BRANCH}" + sh "sudo rm -rf icn build/ubuntu icn-ubuntu-18.04.iso" + sh "git clone https://gerrit.akraino.org/r/icn" + dir("icn") { + sh "git fetch origin ${GERRIT_REFSPEC}:${changeBranch}" + sh "git checkout ${changeBranch}" + sh "git rebase origin/${GERRIT_BRANCH}" + } + sh "sudo icn/tools/setup_build_machine.sh" + // sh "sudo icn/tools/collect.sh" + sh "sudo icn/tools/create_usb_bootable.sh" } } } + post { + always { + archiveArtifacts artifacts: "icn-ubuntu-18.04.iso", onlyIfSuccessful: true + } + } } diff --git a/ci/README.md b/ci/README.md new file mode 100644 index 0000000..c368dc3 --- /dev/null +++ b/ci/README.md @@ -0,0 +1,24 @@ +# Setup a private Jenkins server from a refresh ubuntu + + +**Note:** As we don't support that downloading packages in sandbox for now, +it means that the packages are all downloaded directely from the jenkins +server. So that the jenkins server must have the same OS version with ICN +nodes. Currently, it's ubuntu 18.04 with kernel version 4.15.0-45-generic. + +## How to setup jenkins server + +Put the gerrit ssh key under `icn/ci/gerrit.key` +The default listening address is the default ip address of the Jenkins server. +To override the listening address/domain name, use variable `jenkins_hostname`. +The default Jenkins username/password is `admin/admin`. To overrides it, use variables +`jenkins_admin_username` and `jenkins_admin_password`. + +```bash +git clone "https://gerrit.akraino.org/r/icn" # may need to switch the branch based on your case +cd icn/ci +sudo ./setup_jenkins.sh +sudo ansible-playbook site_jenkins.yaml -v +``` + +Once the playbook is successful, we can visite the jenkins server at http://:8080. diff --git a/ci/gerrit.groovy b/ci/gerrit.groovy new file mode 100644 index 0000000..38d3076 --- /dev/null +++ b/ci/gerrit.groovy @@ -0,0 +1,34 @@ +import jenkins.* +import jenkins.model.* +import hudson.* +import hudson.model.* +import com.sonyericsson.hudson.plugins.gerrit.trigger.config.Config +import com.sonyericsson.hudson.plugins.gerrit.trigger.GerritServer +import com.sonyericsson.hudson.plugins.gerrit.trigger.PluginImpl + + +def gerrit_server_name = 'gerrit.akraino.org' +def gerrit_hostname = 'gerrit.akraino.org' +def gerrit_key_path = '/var/lib/jenkins/.ssh/gerrit.key' +def gerrit_url = 'https://gerrit.akraino.org/' +def gerrit_username = 'icn.jenkins' + +if (PluginImpl.getInstance().getServer(gerrit_server_name) == null) { + GerritServer defaultServer = new GerritServer(gerrit_server_name) + Config config = defaultServer.getConfig() + PluginImpl.getInstance().addServer(defaultServer) + defaultServer.start() + // setting properties + config.setGerritHostName(gerrit_hostname) + config.setGerritFrontEndURL(gerrit_url) + config.setGerritUserName(gerrit_username) + config.setGerritAuthKeyFile(new File(gerrit_key_path)) +} else { + Config config = PluginImpl.getInstance().getServer(gerrit_server_name).getConfig() + config.setGerritHostName(gerrit_hostname) + config.setGerritFrontEndURL(gerrit_url) + config.setGerritUserName(gerrit_username) + config.setGerritAuthKeyFile(new File(gerrit_key_path)) + PluginImpl.getInstance().save() +} +return "success" diff --git a/ci/icn_check.xml b/ci/icn_check.xml new file mode 100644 index 0000000..668f711 --- /dev/null +++ b/ci/icn_check.xml @@ -0,0 +1,105 @@ + + + + + + + + + + skipDefaultCheckout + + + + ICN CI job + false + + + + + + + + PLAIN + icn + + + ANT + ** + + + false + + + + + false + false + false + false + + 0 + 1 + 0 + -1 + 0 + -1 + false + + false + true + PLAIN + + BASE64 + PLAIN + BASE64 + + ci failed + ci pass + + + + + gerrit.akraino.org + + + false + false + false + false + false + + + false + + + + + + + + + 2 + + + origin + https://gerrit.akraino.org/r/icn.git + + + + + origin/${GERRIT_BRANCH} + + + false + + + + + + Jenkinsfile + true + + + false + \ No newline at end of file diff --git a/ci/setup_jenkins.sh b/ci/setup_jenkins.sh new file mode 100755 index 0000000..dfb523e --- /dev/null +++ b/ci/setup_jenkins.sh @@ -0,0 +1,4 @@ +export DEBIAN_FRONTEND=noninteractive +apt update +apt install -y ansible +ansible-galaxy install geerlingguy.jenkins,3.7.0 --roles-path /etc/ansible/roles diff --git a/ci/site_jenkins.yaml b/ci/site_jenkins.yaml new file mode 100644 index 0000000..1510fc8 --- /dev/null +++ b/ci/site_jenkins.yaml @@ -0,0 +1,89 @@ +- hosts: localhost + vars: + jenkins_hostname: "{{ ansible_default_ipv4.address }}" + jenkins_version: 2.192 + jenkins_plugin_timeout: 360 + jenkins_plugins: + - gerrit-trigger + - workflow-aggregator + - git + roles: + - role: geerlingguy.java + become: yes + - role: geerlingguy.jenkins + become: yes + tasks: + - name: restart jenkins to use new installed plugins + meta: flush_handlers + + - name: Wait for Jenkins to start up before proceeding. + command: > + curl -D - --silent --max-time 5 http://{{ jenkins_hostname }}:{{ jenkins_http_port }}{{ jenkins_url_prefix }}/cli/ + args: + warn: false + register: result + until: > + (result.stdout.find("403 Forbidden") != -1) + or (result.stdout.find("200 OK") != -1) + and (result.stdout.find("Please wait while") == -1) + retries: "{{ jenkins_connection_retries | default(60) }}" + delay: "{{ jenkins_connection_delay | default(5) }}" + changed_when: false + check_mode: false + + - name: create directory /var/lib/jenkins/.ssh + file: + path: /var/lib/jenkins/.ssh + owner: jenkins + group: jenkins + state: directory + + - name: place gerrit ssh key + copy: + src: "{{ gerrit_key_path | default('gerrit.key') }}" + dest: /var/lib/jenkins/.ssh/gerrit.key + owner: jenkins + group: jenkins + mode: '0600' + tags: [gerrit] + + - name: grant jenkins user sudo + copy: + content: "jenkins ALL=(ALL) NOPASSWD: ALL" + dest: /etc/sudoers.d/jenkins + owner: root + group: root + mode: '0660' + tags: [gerrit] + + - name: add gerrit server + jenkins_script: + script: "{{lookup('file', 'gerrit.groovy')}}" + url: "http://{{ jenkins_hostname }}:{{ jenkins_http_port }}{{ jenkins_url_prefix }}" + user: "{{ jenkins_admin_username }}" + password: "{{ jenkins_admin_password }}" + validate_certs: no + register: result + failed_when: "'Result: success\n' != result.output" + tags: [gerrit] + + - name: Install python-pip + apt: + name: python-pip + tags: [jobs] + + - name: Install python-jenkins and lxml(required by jenkins_job module) + pip: + name: + - python-jenkins + - lxml + tags: [jobs] + + - name: Add pipeline job for ICN CI + jenkins_job: + name: icn_check + config: "{{lookup('file', 'icn_check.xml')}}" + url: "http://{{ jenkins_hostname }}:{{ jenkins_http_port }}{{ jenkins_url_prefix }}" + user: "{{ jenkins_admin_username }}" + password: "{{ jenkins_admin_password }}" + tags: [jobs]