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
+ }
+ }
}
--- /dev/null
+# 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://<listen_address>:8080.
--- /dev/null
+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"
--- /dev/null
+<?xml version='1.1' encoding='UTF-8'?>
+<flow-definition plugin="workflow-job@2.35">
+ <actions>
+ <org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobAction plugin="pipeline-model-definition@1.3.9"/>
+ <org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobPropertyTrackerAction plugin="pipeline-model-definition@1.3.9">
+ <jobProperties/>
+ <triggers/>
+ <parameters/>
+ <options>
+ <string>skipDefaultCheckout</string>
+ </options>
+ </org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobPropertyTrackerAction>
+ </actions>
+ <description>ICN CI job</description>
+ <keepDependencies>false</keepDependencies>
+ <properties>
+ <org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
+ <triggers>
+ <com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger plugin="gerrit-trigger@2.30.0">
+ <spec></spec>
+ <gerritProjects>
+ <com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.GerritProject>
+ <compareType>PLAIN</compareType>
+ <pattern>icn</pattern>
+ <branches>
+ <com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Branch>
+ <compareType>ANT</compareType>
+ <pattern>**</pattern>
+ </com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.Branch>
+ </branches>
+ <disableStrictForbiddenFileVerification>false</disableStrictForbiddenFileVerification>
+ </com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.GerritProject>
+ </gerritProjects>
+ <dynamicGerritProjects class="empty-list"/>
+ <skipVote>
+ <onSuccessful>false</onSuccessful>
+ <onFailed>false</onFailed>
+ <onUnstable>false</onUnstable>
+ <onNotBuilt>false</onNotBuilt>
+ </skipVote>
+ <gerritBuildSuccessfulVerifiedValue>0</gerritBuildSuccessfulVerifiedValue>
+ <gerritBuildSuccessfulCodeReviewValue>1</gerritBuildSuccessfulCodeReviewValue>
+ <gerritBuildFailedVerifiedValue>0</gerritBuildFailedVerifiedValue>
+ <gerritBuildFailedCodeReviewValue>-1</gerritBuildFailedCodeReviewValue>
+ <gerritBuildUnstableVerifiedValue>0</gerritBuildUnstableVerifiedValue>
+ <gerritBuildUnstableCodeReviewValue>-1</gerritBuildUnstableCodeReviewValue>
+ <silentMode>false</silentMode>
+ <notificationLevel></notificationLevel>
+ <silentStartMode>false</silentStartMode>
+ <escapeQuotes>true</escapeQuotes>
+ <nameAndEmailParameterMode>PLAIN</nameAndEmailParameterMode>
+ <dependencyJobsNames></dependencyJobsNames>
+ <commitMessageParameterMode>BASE64</commitMessageParameterMode>
+ <changeSubjectParameterMode>PLAIN</changeSubjectParameterMode>
+ <commentTextParameterMode>BASE64</commentTextParameterMode>
+ <buildStartMessage></buildStartMessage>
+ <buildFailureMessage>ci failed</buildFailureMessage>
+ <buildSuccessfulMessage>ci pass</buildSuccessfulMessage>
+ <buildUnstableMessage></buildUnstableMessage>
+ <buildNotBuiltMessage></buildNotBuiltMessage>
+ <buildUnsuccessfulFilepath></buildUnsuccessfulFilepath>
+ <customUrl></customUrl>
+ <serverName>gerrit.akraino.org</serverName>
+ <triggerOnEvents>
+ <com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.events.PluginPatchsetCreatedEvent>
+ <excludeDrafts>false</excludeDrafts>
+ <excludeTrivialRebase>false</excludeTrivialRebase>
+ <excludeNoCodeChange>false</excludeNoCodeChange>
+ <excludePrivateState>false</excludePrivateState>
+ <excludeWipState>false</excludeWipState>
+ </com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.events.PluginPatchsetCreatedEvent>
+ </triggerOnEvents>
+ <dynamicTriggerConfiguration>false</dynamicTriggerConfiguration>
+ <triggerConfigURL></triggerConfigURL>
+ <triggerInformationAction/>
+ </com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger>
+ </triggers>
+ </org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
+ </properties>
+ <definition class="org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition" plugin="workflow-cps@2.74">
+ <scm class="hudson.plugins.git.GitSCM" plugin="git@3.12.1">
+ <configVersion>2</configVersion>
+ <userRemoteConfigs>
+ <hudson.plugins.git.UserRemoteConfig>
+ <name>origin</name>
+ <url>https://gerrit.akraino.org/r/icn.git</url>
+ </hudson.plugins.git.UserRemoteConfig>
+ </userRemoteConfigs>
+ <branches>
+ <hudson.plugins.git.BranchSpec>
+ <name>origin/${GERRIT_BRANCH}</name>
+ </hudson.plugins.git.BranchSpec>
+ </branches>
+ <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
+ <submoduleCfg class="list"/>
+ <extensions>
+ <hudson.plugins.git.extensions.impl.CleanBeforeCheckout/>
+ </extensions>
+ </scm>
+ <scriptPath>Jenkinsfile</scriptPath>
+ <lightweight>true</lightweight>
+ </definition>
+ <triggers/>
+ <disabled>false</disabled>
+</flow-definition>
\ No newline at end of file
--- /dev/null
+export DEBIAN_FRONTEND=noninteractive
+apt update
+apt install -y ansible
+ansible-galaxy install geerlingguy.jenkins,3.7.0 --roles-path /etc/ansible/roles
--- /dev/null
+- 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]