diff --git a/Jenkinsfile b/Jenkinsfile index c35e3f19..b6f26d9a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,6 +2,9 @@ pipeline { agent { label 'llrgrhgtrig.in2p3.fr' } + triggers { + issueCommentTrigger('.*Build*') + } environment { LABEL_TEST='test' LABEL_REF='ref' @@ -25,6 +28,7 @@ pipeline { echo "log_Jenkins does not exist." fi echo '==> Set environment variables' + echo '== Start testing webhooks ==' ''' script{ String s = env.JOB_NAME @@ -200,6 +204,7 @@ pipeline { stage('Install CMSSW Test release'){ steps { sh ''' + echo "Testing" ./HGCTPGValidation/scripts/installCMSSW_global.sh $SCRAM_ARCH $REF_RELEASE $REMOTE $BASE_REMOTE $CHANGE_BRANCH $CHANGE_TARGET ${LABEL_TEST} echo ' ' ''' @@ -301,6 +306,55 @@ pipeline { println( "Validation of the validation: Set the original name of CHANGE_BRANCH => " + env.CHANGE_BRANCH ) } + // Comments + def commentCauses = currentBuild.getBuildCauses("com.adobe.jenkins.github_pr_comment_build.GitHubPullRequestCommentCause") + if (commentCauses) { + for (def commentCause : commentCauses) { + echo("""Comment Author: ${commentCause.commentAuthor}, Body: "${commentCause.commentBody}" (${commentCause.commentUrl})""") + } + } else { + echo("Build was not started by a PR comment") + } + + // Labels + def labelCauses = currentBuild.getBuildCauses("com.adobe.jenkins.github_pr_comment_build.GitHubPullRequestLabelCause") + if (labelCauses) { + for (def labelCause : labelCauses) { + echo("""Label Author: ${labelCause.labellingAuthor}, Label: "${labelCause.label}" (${labelCause.labelUrl})""") + } + } else { + echo("Build was not started by a PR label") + } + + // Reviews + def reviewCauses = currentBuild.getBuildCauses("com.adobe.jenkins.github_pr_comment_build.GitHubPullRequestReviewCause") + if (reviewCauses) { + for (def reviewCause : reviewCauses) { + echo("""Review Author: ${reviewCause.reviewAuthor} (${reviewCause.pullRequestUrl})""") + } + } else { + echo("Build was not started by a PR review") + } + + // Updates + def updateCauses = currentBuild.getBuildCauses("com.adobe.jenkins.github_pr_comment_build.GitHubPullRequestUpdateCause") + if (updateCauses) { + for (def updateCause : updateCauses) { + echo("""Update Author: ${updateCause.updateAuthor} (${updateCause.pullRequestUrl})""") + } + } else { + echo("Build was not started by a PR update") + } + + // Detecting whether a build was started by the trigger in a script + if(currentBuild.upstreamBuilds){ + print("Parent") + print(currentBuild.upstreamBuilds[0].getBuildCauses()[0].userId) + } else { + print("No parent") + print(currentBuild.getBuildCauses()[0].userId) + } + def message = "" if (currentBuild.result == 'SUCCESS') { message = "The validation checks have passed." + "
" + "The comparison histograms are available [here](${env.WEBPAGES_VAL}list_config.php?pr=/PR$CHANGE_ID)" diff --git a/scripts/write_toGitHub.sh b/scripts/write_toGitHub.sh index b84ff1ae..51ec8094 100755 --- a/scripts/write_toGitHub.sh +++ b/scripts/write_toGitHub.sh @@ -22,9 +22,9 @@ set +x exec >> log_Jenkins; module use /opt/exp_soft/vo.llr.in2p3.fr/modulefiles_el7/; module purge; module load python/3.9.9; # For the organization hgc-tpg -python /data/jenkins/workspace/create_token_hgc-tpg.py > /tmp/github_token +#python /data/jenkins/workspace/create_token_hgc-tpg.py > /tmp/github_token # For the organization test-org-hgctpg -#python /data/jenkins/workspace/create_token.py > /tmp/github_token +python /data/jenkins/workspace/create_token.py > /tmp/github_token # Compose the url to be used for printing the message in the GitHub PR thread # In the string "url" replace "pull" with "issues" and add at the end "comments"