Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check a PR has been committed using git signoff #439

Merged
merged 3 commits into from
Aug 3, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions jenkins/Jenkinsfile.premerge
Original file line number Diff line number Diff line change
Expand Up @@ -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"
sameerz marked this conversation as resolved.
Show resolved Hide resolved
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"
Expand All @@ -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'")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's an issue here where if grep fails to find a match it will return a non-zero exit code. That in turn will cause the pipeline command to return a non-zero exit code which will cause the sh command to throw an exception as described here. I think this either needs to use the returnStatus: true option and switch off the result code of the step or do something like this to avoid grep failing to match to cause a pipeline failure:

Suggested change
script: "git show ${commit} --shortstat | grep 'Signed-off-by'")
script: "git show ${commit} --shortstat | grep 'Signed-off-by || echo'")

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
}