I'm new to DevOps, and am cobbling together a beginner understanding from lots of reading, YouTube videos, and online examples.
I've had initial success adapting this helpful tutorial. I.e. in my bitbucket project, I've introduced a webhook that posts to Jenkins' generic pipeline url. The script referenced in the video is here. My (simplified) adaptation is:
node {
properties([
pipelineTriggers([
[$class: 'GenericTrigger',
genericVariables: [
[ key: 'committer_name', value: '$.actor.name' ],
[ key: 'committer_email', value: '$.actor.emailAddress' ],
[ key: 'ref', value: '$.changes[0].refId'],
[ key: 'tag', value: '$.changes[0].ref.id', regexpFilter: 'refs/tags/'],
[ key: 'commit', value: '$.changes[0].toHash' ],
[ key: 'repo_slug', value: '$.repository.slug' ],
[ key: 'project_key', value: '$.repository.project.key' ],
[ key: 'clone_url', value: '$.repository.links.clone[0].href' ],
[ key: 'var1', value: 'value1' ],
[ key: 'var2', value: 'value2' ],
[ key: 'var3', value: 'value3' ],
[ key: 'var4', value: 'value4' ]
],
causeString: '$committer_name pushed tag $tag to $clone_url referencing $commit',
token: 'my_token',
printContributedVariables: true,
printPostContent: true,
regexpFilterText: '$ref',
regexpFilterExpression: '^refs/tags/.*'
]
])
])
stage("Prepare") {
deleteDir()
sh '''
echo $committer_name
echo $committer_email
echo $var1
echo $var2
'''
}
}
Following is console output from one run of this job:
user pushed tag wip35 to https://bitbucket.someplace.com/scm/san/user_generic_webhook_sender.git referencing 24e71eaa1a9f92fd850135798a4177e810a926ab
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on builder-231 in /home/builder/workspace/on_this_project_generic_webhook_build_that_project
[Pipeline] {
GenericWebhookEnvironmentContributor
Received:
{"eventKey":"repo:refs_changed","date":"2021-05-13T16:02:29-0700","actor":{"name":"user","emailAddress":"[email protected]","id":4464,"displayName":"user","active":true,"slug":"user","type":"NORMAL","links":{"self":[{"href":"https://bitbucket.someplace.com/users/user"}]}},"repository":{"slug":"user_generic_webhook_sender","id":4285,"name":"user_generic_webhook_sender","description":"Sends generic webbooks to Jenkins","scmId":"git","state":"AVAILABLE","statusMessage":"Available","forkable":true,"project":{"key":"SAN","id":2280,"name":"sandbox_projects","description":"sandbox_projects_prj","public":true,"type":"NORMAL","links":{"self":[{"href":"https://bitbucket.someplace.com/projects/SAN"}]}},"public":false,"links":{"clone":[{"href":"https://bitbucket.someplace.com/scm/san/user_generic_webhook_sender.git","name":"http"},{"href":"ssh://[email protected]:7999/san/user_generic_webhook_sender.git","name":"ssh"}],"self":[{"href":"https://bitbucket.someplace.com/projects/SAN/repos/user_generic_webhook_sender/browse"}]}},"changes":[{"ref":{"id":"refs/tags/wip35","displayId":"wip35","type":"TAG"},"refId":"refs/tags/wip35","fromHash":"0000000000000000000000000000000000000000","toHash":"24e71eaa1a9f92fd850135798a4177e810a926ab","type":"ADD"}]}
Contributing variables:
clone_url = https://bitbucket.someplace.com/scm/san/user_generic_webhook_sender.git
commit = 24e71eaa1a9f92fd850135798a4177e810a926ab
committer_email = [email protected]
committer_name = user
project_key = SAN
ref = refs/tags/wip35
repo_slug = user_generic_webhook_sender
tag = wip35
var1 =
var2 =
[Pipeline] properties
[Pipeline] stage
[Pipeline] { (Prepare)
[Pipeline] deleteDir
[Pipeline] sh
+ echo user
user
+ echo [email protected]
[email protected]
+ echo
+ echo
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
Question: Why are $var1
and $var2
empty during the stage execution, whereas $committer_name
and $committer_email
have the values that were assigned in the genericVariables
section of the Pipeline script?