diff options
author | Christian Poessinger <christian@poessinger.com> | 2019-09-15 11:07:28 +0200 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2019-09-15 11:19:13 +0200 |
commit | 31e9295cd06a3b519a6513e9976042b41789428e (patch) | |
tree | a85cad656d20e02f6e66ee2ce8629e055632d942 /Jenkinsfile | |
parent | 47b95b15b3168a9fc7183961e40fd20601a74066 (diff) | |
download | vyos-build-31e9295cd06a3b519a6513e9976042b41789428e.tar.gz vyos-build-31e9295cd06a3b519a6513e9976042b41789428e.zip |
Jenkins: add function to set GitHub build status
Diffstat (limited to 'Jenkinsfile')
-rw-r--r-- | Jenkinsfile | 74 |
1 files changed, 47 insertions, 27 deletions
diff --git a/Jenkinsfile b/Jenkinsfile index bcf1bdb..6d0c87b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -56,6 +56,23 @@ def setDescription() { item.save() } +def setGitHubStatus(message) { + if (isCustomBuild()) + return + + withCredentials([string(credentialsId: 'GitHub-API-Token', variable: 'TOKEN')]) { + sh "env" + sh """ + curl -XPOST -H "Authorization: token ${TOKEN}" https://api.github.com/repos/vyos/vyos-build/statuses/\$(git rev-parse HEAD) -d "{ + \"state\": \"pending\", + \"target_url\": \"${BUILD_URL}\", + \"description\": \"${message}\", + \"context\": \"continuous-integration/jenkins\" + }" + """ + } +} + /* Only keep the 10 most recent builds. */ def projectProperties = [ [$class: 'BuildDiscarderProperty',strategy: [$class: 'LogRotator', numToKeepStr: '1']], @@ -84,10 +101,12 @@ pipeline { stages { stage('Configure') { steps { - sh """ - pwd - ./configure --build-by="autobuild@vyos.net" --debian-mirror="http://ftp.us.debian.org/debian/" - """ + script { + setGitHubStatus("Build is pending!") + sh """ + ./configure --build-by="autobuild@vyos.net" --debian-mirror="http://ftp.us.debian.org/debian/" + """ + } } } stage('Build') { @@ -104,29 +123,30 @@ pipeline { sshagent(['SSH-dev.packages.vyos.net']) { script { // only deploy ISO if build from official repository - if (! isCustomBuild()) { - // build up some fancy groovy variables so we do not need to write/copy - // every option over and over again! - def ARCH = sh(returnStdout: true, script: "dpkg --print-architecture").trim() - def SSH_DIR = '/home/sentrium/web/downloads.vyos.io/public_html/rolling/' + getGitBranchName() + '/' + ARCH - def SSH_OPTS = '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' - def SSH_REMOTE = 'khagen@10.217.48.113' - - // No need to explicitly check the return code. The pipeline - // will fail if sh returns a non 0 exit code - sh """ - ssh ${SSH_OPTS} ${SSH_REMOTE} -t "bash --login -c 'mkdir -p ${SSH_DIR}'" - """ - sh """ - ssh ${SSH_OPTS} ${SSH_REMOTE} -t "bash --login -c 'mkdir -p ${SSH_DIR}'" - """ - sh """ - ssh ${SSH_OPTS} ${SSH_REMOTE} -t "bash --login -c 'find ${SSH_DIR} -type f -mtime +14 -exec rm -f {} \\;'" - """ - sh """ - scp ${SSH_OPTS} build/vyos*.iso ${SSH_REMOTE}:${SSH_DIR}/ - """ - } + if (isCustomBuild()) + return + + // build up some fancy groovy variables so we do not need to write/copy + // every option over and over again! + def ARCH = sh(returnStdout: true, script: "dpkg --print-architecture").trim() + def SSH_DIR = '/home/sentrium/web/downloads.vyos.io/public_html/rolling/' + getGitBranchName() + '/' + ARCH + def SSH_OPTS = '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' + def SSH_REMOTE = 'khagen@10.217.48.113' + + // No need to explicitly check the return code. The pipeline + // will fail if sh returns a non 0 exit code + sh """ + ssh ${SSH_OPTS} ${SSH_REMOTE} -t "bash --login -c 'mkdir -p ${SSH_DIR}'" + """ + sh """ + ssh ${SSH_OPTS} ${SSH_REMOTE} -t "bash --login -c 'mkdir -p ${SSH_DIR}'" + """ + sh """ + ssh ${SSH_OPTS} ${SSH_REMOTE} -t "bash --login -c 'find ${SSH_DIR} -type f -mtime +14 -exec rm -f {} \\;'" + """ + sh """ + scp ${SSH_OPTS} build/vyos*.iso ${SSH_REMOTE}:${SSH_DIR}/ + """ } } } |