From 47b95b15b3168a9fc7183961e40fd20601a74066 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sun, 15 Sep 2019 11:00:02 +0200 Subject: Jenkins: only deploy ISO if build from official repository --- Jenkinsfile | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index ee5b7528..bcf1bdb1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -103,27 +103,30 @@ pipeline { // publish build result, using SSH-dev.packages.vyos.net Jenkins Credentials sshagent(['SSH-dev.packages.vyos.net']) { script { - // 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' + // 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}/ - """ + // 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}/ + """ + } } } } -- cgit v1.2.3 From 31e9295cd06a3b519a6513e9976042b41789428e Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sun, 15 Sep 2019 11:07:28 +0200 Subject: Jenkins: add function to set GitHub build status --- Jenkinsfile | 74 +++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 27 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index bcf1bdb1..6d0c87b8 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}/ + """ } } } -- cgit v1.2.3 From 38f06da2873119310e1c83beb90dd3958c99a517 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sun, 15 Sep 2019 11:17:37 +0200 Subject: Jenkins: set timeout to 90 minutes --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 6d0c87b8..c4993982 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -84,7 +84,7 @@ setDescription() pipeline { options { disableConcurrentBuilds() - timeout(time: 4, unit: 'HOURS') + timeout(time: 90, unit: 'MINUTES') parallelsAlwaysFailFast() } triggers { -- cgit v1.2.3 From c8302cd6fcac53ce7d20e8fbfe9db5d3dc3a2cd3 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sun, 15 Sep 2019 12:06:35 +0200 Subject: Jenkins: fix GitHub JSON API interface --- Jenkinsfile | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index c4993982..68e0e724 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -56,20 +56,21 @@ def setDescription() { item.save() } -def setGitHubStatus(message) { +def setGitHubStatus(state, description) { 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\" - }" - """ + def commitId = sh(returnStdout: true, script: "git rev-parse HEAD").trim() + def postBody = [ + state: "${state}", + target_url: "${BUILD_URL}", + description: "${description}", + context: 'continuous-integration/jenkins', + ] + def postBodyString = groovy.json.JsonOutput.toJson(postBody) + sh "curl 'https://api.github.com/repos/vyos/vyos-build/statuses/${commitId}?access_token=${TOKEN}' \ + -H 'Content-Type: application/json' -X POST -d '${postBodyString}' -k" } } @@ -102,7 +103,7 @@ pipeline { stage('Configure') { steps { script { - setGitHubStatus("Build is pending!") + setGitHubStatus("pending", "Build pending") sh """ ./configure --build-by="autobuild@vyos.net" --debian-mirror="http://ftp.us.debian.org/debian/" """ -- cgit v1.2.3 From cc3f12cd93aa705433ce92a468ffc70c17860142 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sun, 15 Sep 2019 12:37:38 +0200 Subject: Jenkins: set GitHub build info on failure/success --- Jenkinsfile | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 68e0e724..4383f230 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -103,7 +103,7 @@ pipeline { stage('Configure') { steps { script { - setGitHubStatus("pending", "Build pending") + setGitHubStatus("pending", "Build is pending.") sh """ ./configure --build-by="autobuild@vyos.net" --debian-mirror="http://ftp.us.debian.org/debian/" """ @@ -120,13 +120,13 @@ pipeline { } post { success { - // publish build result, using SSH-dev.packages.vyos.net Jenkins Credentials - sshagent(['SSH-dev.packages.vyos.net']) { - script { - // only deploy ISO if build from official repository - if (isCustomBuild()) - return + script { + // only deploy ISO if build from official repository + if (isCustomBuild()) + return + // publish build result, using SSH-dev.packages.vyos.net Jenkins Credentials + sshagent(['SSH-dev.packages.vyos.net']) { // 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() @@ -149,6 +149,17 @@ pipeline { scp ${SSH_OPTS} build/vyos*.iso ${SSH_REMOTE}:${SSH_DIR}/ """ } + + setGitHubStatus("success", "Build has succeeded!") + } + } + failure { + script { + // only deploy ISO if build from official repository + if (isCustomBuild()) + return + + setGitHubStatus("failure", "Build has failed!") } } cleanup { -- cgit v1.2.3