From ca4e0ba22c072ce01ada4113ab7e331f8269681e Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Mon, 16 Oct 2017 19:47:52 -0400 Subject: [PATCH 1/4] jenkins: add http-parser.jenkinsfile --- jenkins/http-parser.jenkinsfile | 87 +++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 jenkins/http-parser.jenkinsfile diff --git a/jenkins/http-parser.jenkinsfile b/jenkins/http-parser.jenkinsfile new file mode 100644 index 000000000..c04896467 --- /dev/null +++ b/jenkins/http-parser.jenkinsfile @@ -0,0 +1,87 @@ +#!/usr/bin/env groovy + +import groovy.json.JsonOutput + +pipeline { + agent any + + parameters { + booleanParam(name: 'CERTIFY_SAFE', defaultValue: false, description: 'I have reviewed *the latest version of* these changes and I am sure that they don’t contain any code that could compromise the security of the CI infrastructure.') + string(defaultValue: "", description: 'The numeric ID of the pull request (from GitHub URL)', name: 'PR_ID') + } + + stages { + stage('Clone repository') { + steps { + git 'https://github.com/nodejs/http-parser.git' + } + } + + stage('Setup Git repository') { + when { + expression { + return !!env.PR_ID + } + } + + steps { + sh "git fetch origin pull/${env.PR_ID}/head:totest" + sh 'git checkout totest' + } + } + + stage('Setup build dependencies') { + steps { + echo "Testing: ${sh(returnStdout: true, script: 'git log -1 --oneline').trim()}" + + sh 'gcc --version' + sendBuildStatus("pending", env.PR_ID, env.BUILD_URL) + } + } + + stage('Run tests') { + steps { + sh 'make' + } + } + } + + post { + success { + sendBuildStatus("success", env.PR_ID, env.BUILD_URL) + } + + failure { + sendBuildStatus("failure", env.PR_ID, env.BUILD_URL) + } + } +} + +def sendBuildStatus(status, prId, buildUrl) { + if (!prId) { return } + + def path = "" + def message = "" + + if (status == "success") { + message = "tests passed" + path = "end" + } else if (status == "failure") { + message = "tests failed" + path = "end" + } else if (status == "pending") { + message = "checking for errors" + path = "start" + } + + def buildPayload = JsonOutput.toJson([ + 'identifier': 'test', + 'status': status, + 'message': message, + 'commit': sh(returnStdout: true, script: 'git rev-parse HEAD').trim(), + 'url': buildUrl, + 'ref': "refs/pull/${env.PR_ID}/head" + ]) + + sh(returnStdout: true, script: "curl -H 'Content-Type: application/json' -X POST -d '${buildPayload}' http://9d7d96c6.ngrok.io/http-parser/jenkins/${path}") +} From 7c2da1d3be2db79b65e20035eabb503f80cb19ac Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Tue, 31 Oct 2017 19:39:23 -0400 Subject: [PATCH 2/4] [squash] change cloning strategy --- jenkins/http-parser.jenkinsfile | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/jenkins/http-parser.jenkinsfile b/jenkins/http-parser.jenkinsfile index c04896467..f39cce401 100644 --- a/jenkins/http-parser.jenkinsfile +++ b/jenkins/http-parser.jenkinsfile @@ -3,30 +3,27 @@ import groovy.json.JsonOutput pipeline { - agent any + agent { label 'jenkins-workspace' } parameters { booleanParam(name: 'CERTIFY_SAFE', defaultValue: false, description: 'I have reviewed *the latest version of* these changes and I am sure that they don’t contain any code that could compromise the security of the CI infrastructure.') string(defaultValue: "", description: 'The numeric ID of the pull request (from GitHub URL)', name: 'PR_ID') + string(defaultValue: 'master', description: 'Git branch to use for testing (ignore this value for PRs)', name: 'BRANCH') } stages { - stage('Clone repository') { + stage("Setup repository") { steps { - git 'https://github.com/nodejs/http-parser.git' - } - } - - stage('Setup Git repository') { - when { - expression { - return !!env.PR_ID - } - } - - steps { - sh "git fetch origin pull/${env.PR_ID}/head:totest" - sh 'git checkout totest' + checkout(poll: false, scm: [ + $class: 'GitSCM', + branches: [[ + name: (params.PR_ID ? "pr/${params.PR_ID}/head" : params.BRANCH) + ]], + userRemoteConfigs: [[ + url: "https://github.com/nodejs/http-parser", + refspec: '+refs/pull/*:refs/remotes/origin/pr/* +refs/heads/*:refs/remotes/origin/*', + ]] + ]) } } From 34c6cb429dd726c837789e925e2c95f4a95badab Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Sun, 5 Nov 2017 13:54:05 -0500 Subject: [PATCH 3/4] [squash] use post-build-status-update --- jenkins/http-parser.jenkinsfile | 39 ++++++++++----------------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/jenkins/http-parser.jenkinsfile b/jenkins/http-parser.jenkinsfile index f39cce401..997bd4537 100644 --- a/jenkins/http-parser.jenkinsfile +++ b/jenkins/http-parser.jenkinsfile @@ -32,7 +32,7 @@ pipeline { echo "Testing: ${sh(returnStdout: true, script: 'git log -1 --oneline').trim()}" sh 'gcc --version' - sendBuildStatus("pending", env.PR_ID, env.BUILD_URL) + sendBuildStatus("pending", env.PR_ID, env.BUILD_URL, env.GIT_COMMIT) } } @@ -45,40 +45,23 @@ pipeline { post { success { - sendBuildStatus("success", env.PR_ID, env.BUILD_URL) + sendBuildStatus("success", env.PR_ID, env.BUILD_URL, env.GIT_COMMIT) } failure { - sendBuildStatus("failure", env.PR_ID, env.BUILD_URL) + sendBuildStatus("failure", env.PR_ID, env.BUILD_URL, env.GIT_COMMIT) } } } -def sendBuildStatus(status, prId, buildUrl) { +def sendBuildStatus(status, prId, buildUrl, commit) { if (!prId) { return } - def path = "" - def message = "" - - if (status == "success") { - message = "tests passed" - path = "end" - } else if (status == "failure") { - message = "tests failed" - path = "end" - } else if (status == "pending") { - message = "checking for errors" - path = "start" - } - - def buildPayload = JsonOutput.toJson([ - 'identifier': 'test', - 'status': status, - 'message': message, - 'commit': sh(returnStdout: true, script: 'git rev-parse HEAD').trim(), - 'url': buildUrl, - 'ref': "refs/pull/${env.PR_ID}/head" - ]) - - sh(returnStdout: true, script: "curl -H 'Content-Type: application/json' -X POST -d '${buildPayload}' http://9d7d96c6.ngrok.io/http-parser/jenkins/${path}") + build job: 'post-build-status-update', parameters: [ + string(name: 'REPO', value: 'http-parser'), + string(name: 'IDENTIFIER', value: 'test'), + string(name: 'URL', value: buildUrl), + string(name: 'COMMIT', value: commit), + string(name: 'REF', value: "refs/pull/${env.PR_ID}/head"), + ] } From 80835e340bda194d3adc79a37b024e80ec885664 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Tue, 7 Nov 2017 12:47:49 -0500 Subject: [PATCH 4/4] name first --- jenkins/http-parser.jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jenkins/http-parser.jenkinsfile b/jenkins/http-parser.jenkinsfile index 997bd4537..ace7523cf 100644 --- a/jenkins/http-parser.jenkinsfile +++ b/jenkins/http-parser.jenkinsfile @@ -7,8 +7,8 @@ pipeline { parameters { booleanParam(name: 'CERTIFY_SAFE', defaultValue: false, description: 'I have reviewed *the latest version of* these changes and I am sure that they don’t contain any code that could compromise the security of the CI infrastructure.') - string(defaultValue: "", description: 'The numeric ID of the pull request (from GitHub URL)', name: 'PR_ID') - string(defaultValue: 'master', description: 'Git branch to use for testing (ignore this value for PRs)', name: 'BRANCH') + string(name: 'PR_ID', defaultValue: "", description: 'The numeric ID of the pull request (from GitHub URL)') + string(name: 'BRANCH', defaultValue: 'master', description: 'Git branch to use for testing (ignore this value for PRs)') } stages {