From 123ca13130c72f20eab15d99d7ad310e2d55a7dc Mon Sep 17 00:00:00 2001 From: Emilia Becheva Date: Thu, 24 Apr 2025 18:25:55 +0200 Subject: [PATCH 01/11] Poll every 1 minute --- Jenkinsfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index c35e3f19..11da0400 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,6 +2,9 @@ pipeline { agent { label 'llrgrhgtrig.in2p3.fr' } + triggers { + pollSCM('H/1 * * * *') // Poll every 1 minute + } environment { LABEL_TEST='test' LABEL_REF='ref' From 7a0cfe458d767f82f4cde02714f1abb3cc203d5c Mon Sep 17 00:00:00 2001 From: Emilia Becheva Date: Thu, 24 Apr 2025 21:05:53 +0200 Subject: [PATCH 02/11] Change to token for test-org-hgctpg --- scripts/write_toGitHub.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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" From 280499880e0a1b0654f2f4605ee3f41f9a0cf646 Mon Sep 17 00:00:00 2001 From: Emilia Becheva Date: Thu, 24 Apr 2025 21:08:29 +0200 Subject: [PATCH 03/11] Get information when trigger build from comments --- Jenkinsfile | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 11da0400..198c6a35 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -304,6 +304,16 @@ 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") + } + 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)" From 912df0edeebddbfb8f5d5069f5e08ab460645f97 Mon Sep 17 00:00:00 2001 From: Emilia Becheva Date: Mon, 28 Apr 2025 15:39:12 +0200 Subject: [PATCH 04/11] Add trigger on comments --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index 198c6a35..d87d6929 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,6 +4,7 @@ pipeline { } triggers { pollSCM('H/1 * * * *') // Poll every 1 minute + issueCommentTrigger('.*Build*') } environment { LABEL_TEST='test' From 7b5d225e5e91e33b94de03e68af58475041e233e Mon Sep 17 00:00:00 2001 From: Emilia Becheva Date: Mon, 28 Apr 2025 15:42:30 +0200 Subject: [PATCH 05/11] Detecting whether a build was started by the trigger in a script --- Jenkinsfile | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index d87d6929..12e344b9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -315,6 +315,16 @@ pipeline { echo("Build was not started by a PR comment") } + // Detecting whether a build was started by the trigger in a script + def triggerCause = currentBuild.rawBuild.getCause(org.jenkinsci.plugins.pipeline.github.trigger.IssueCommentCause) + if (triggerCause) { + echo("Build was started by ${triggerCause.userLogin}, who wrote: " + + "\"${triggerCause.comment}\", which matches the " + + "\"${triggerCause.triggerPattern}\" trigger pattern.") + } else { + echo('Build was not started by a trigger') + } + 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)" From 682cbdb27ac983e7a2f4d67bd0d13d2c17f0fb79 Mon Sep 17 00:00:00 2001 From: Emilia Becheva Date: Mon, 28 Apr 2025 16:55:33 +0200 Subject: [PATCH 06/11] Replace the code using currentBuild.rawBuild.getCause with currentBuild.getBuildCauses --- Jenkinsfile | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 12e344b9..32cf98c4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -316,13 +316,12 @@ pipeline { } // Detecting whether a build was started by the trigger in a script - def triggerCause = currentBuild.rawBuild.getCause(org.jenkinsci.plugins.pipeline.github.trigger.IssueCommentCause) - if (triggerCause) { - echo("Build was started by ${triggerCause.userLogin}, who wrote: " + - "\"${triggerCause.comment}\", which matches the " + - "\"${triggerCause.triggerPattern}\" trigger pattern.") + if(currentBuild.upstreamBuilds){ + print("Parent") + print(currentBuild.upstreamBuilds[0].getBuildCauses()[0].userId) } else { - echo('Build was not started by a trigger') + print("No parent") + print(currentBuild.getBuildCauses()[0].userId) } def message = "" From 1dc9f6246a0fffc9172b461196757f438f08ae5f Mon Sep 17 00:00:00 2001 From: Emilia Becheva Date: Tue, 29 Apr 2025 14:35:27 +0200 Subject: [PATCH 07/11] Delete pollSCM from trigger stage to test webhooks --- Jenkinsfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 32cf98c4..332dd711 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,7 +3,6 @@ pipeline { label 'llrgrhgtrig.in2p3.fr' } triggers { - pollSCM('H/1 * * * *') // Poll every 1 minute issueCommentTrigger('.*Build*') } environment { From 41c925e42c45bf729031ac1c4ca74018d3da447c Mon Sep 17 00:00:00 2001 From: Emilia Becheva Date: Tue, 29 Apr 2025 14:59:08 +0200 Subject: [PATCH 08/11] Add two additional checks to detect what caused the build --- Jenkinsfile | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 332dd711..ded28c38 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -314,6 +314,36 @@ pipeline { 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") From b1b2d6e7b619d0143788b7f80de4db1a510e517d Mon Sep 17 00:00:00 2001 From: Emilia Becheva Date: Mon, 5 May 2025 16:55:49 +0200 Subject: [PATCH 09/11] Add message to test webhooks --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index ded28c38..cccfbd83 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -28,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 From d5194c7667c1b36d6205bd8c98a7e843c2fc0fe2 Mon Sep 17 00:00:00 2001 From: Emilia Becheva Date: Wed, 7 May 2025 15:35:00 +0200 Subject: [PATCH 10/11] Add comment for testing the webhooks --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index cccfbd83..2746b602 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -28,7 +28,7 @@ pipeline { echo "log_Jenkins does not exist." fi echo '==> Set environment variables' - echo 'Start testing webhooks' + echo '== Start testing webhooks ==' ''' script{ String s = env.JOB_NAME From a9bd79e60e73d3df68fa5f5654a7b51383b48ca7 Mon Sep 17 00:00:00 2001 From: Emilia Becheva Date: Mon, 12 May 2025 14:04:10 +0200 Subject: [PATCH 11/11] Add comment for testing build trigger in Jenkins --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index 2746b602..b6f26d9a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -204,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 ' ' '''