From 78c6715ea8578384e2b44038ec2a4c5ef7dda794 Mon Sep 17 00:00:00 2001 From: Tim Liu Date: Tue, 28 Jul 2020 01:28:33 +0800 Subject: [PATCH 1/3] Check a PR has been committed using git signoff Pre-merge build fails without seeing a `-s` signoff from anyone committing to a PR. If the author of a commit adds a single commit with a `-s`, that will be sufficient for the pre-merge build to pass. Signed-off-by: Tim Liu --- jenkins/Jenkinsfile.premerge | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/jenkins/Jenkinsfile.premerge b/jenkins/Jenkinsfile.premerge index bc0375bc01a..edd3e6779a1 100644 --- a/jenkins/Jenkinsfile.premerge +++ b/jenkins/Jenkinsfile.premerge @@ -51,6 +51,12 @@ pipeline { agent { label 'docker-gpu' } steps { script { + //Check if a PR has been committed using git signoff + if (!isSignedOff()) { + echo "Signed-off-by check FAIED" + exit(-1) + } + def CUDA_NAME=sh(returnStdout: true, script: '. jenkins/version-def.sh>&2 && echo -n $CUDA_CLASSIFIER | sed "s/-/./g"') def IMAGE_NAME="$ARTIFACTORY_NAME/sw-spark-docker/plugin:dev-ubuntu16-$CUDA_NAME" @@ -72,3 +78,24 @@ pipeline { } } // end of stages } // end of pipeline + +boolean isSignedOff() { + def target_rev = sh(returnStdout: true, + script: "git rev-parse refs/remotes/origin/${ghprbTargetBranch}").trim() + def revs_arr = sh(returnStdout: true, + script: "git log ${target_rev}..${ghprbActualCommit} --pretty=format:%h").split() + + def signed_off = false + for( String commit : revs_arr ) { + def signed_log = sh(returnStdout: true, + script: "git show ${commit} --shortstat | grep 'Signed-off-by'") + echo "commit: ${commit}, signed_log: ${signed_log}" + // Find `Signed-off-by` comment in one of the commits + if (signed_log?.trim()) { + signed_off = true + break; + } + } + + return signed_off +} From a0f557a51c2f80da8e3c42dd424a0d2ae89446cf Mon Sep 17 00:00:00 2001 From: Sameer Raheja Date: Thu, 30 Jul 2020 22:20:35 -0700 Subject: [PATCH 2/3] Update jenkins/Jenkinsfile.premerge Co-authored-by: Jason Lowe --- jenkins/Jenkinsfile.premerge | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/Jenkinsfile.premerge b/jenkins/Jenkinsfile.premerge index edd3e6779a1..86551cbe0b3 100644 --- a/jenkins/Jenkinsfile.premerge +++ b/jenkins/Jenkinsfile.premerge @@ -53,7 +53,7 @@ pipeline { script { //Check if a PR has been committed using git signoff if (!isSignedOff()) { - echo "Signed-off-by check FAIED" + echo "Signed-off-by check FAILED" exit(-1) } From 309ad7f110da78aa233a5e478a8e8f5c6eebf152 Mon Sep 17 00:00:00 2001 From: Tim Liu Date: Sun, 2 Aug 2020 23:22:09 +0800 Subject: [PATCH 3/3] Append '|| true' to avoid failing to match to cause the pipeline failure --- jenkins/Jenkinsfile.premerge | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/jenkins/Jenkinsfile.premerge b/jenkins/Jenkinsfile.premerge index 86551cbe0b3..23054604795 100644 --- a/jenkins/Jenkinsfile.premerge +++ b/jenkins/Jenkinsfile.premerge @@ -53,8 +53,7 @@ pipeline { script { //Check if a PR has been committed using git signoff if (!isSignedOff()) { - echo "Signed-off-by check FAILED" - exit(-1) + error "Signed-off-by check FAILED" } def CUDA_NAME=sh(returnStdout: true, @@ -88,7 +87,7 @@ boolean isSignedOff() { def signed_off = false for( String commit : revs_arr ) { def signed_log = sh(returnStdout: true, - script: "git show ${commit} --shortstat | grep 'Signed-off-by'") + script: "git show ${commit} --shortstat | grep 'Signed-off-by' || true") echo "commit: ${commit}, signed_log: ${signed_log}" // Find `Signed-off-by` comment in one of the commits if (signed_log?.trim()) {