Reputation: 539
I need simple thing:
I am stacked on point number 2. Is it possible to access the url for repository from which the Jenkinsfile was downloaded? I don't want to hardcode it in Jenkinsfile.
Upvotes: 0
Views: 983
Reputation: 407
I am using scm.userRemoteConfigs[0].url
, but I am not sure whether you need an actual checkout scm
step for the object to be present. The Script Approval is also necessary.
I would like to post this as a comment to the accepted answer but my reputation is too low :(
Upvotes: 0
Reputation: 4628
That's really interesting case! I have assumption that you are using git for checkout Jenkinsfile. So here is code for you:
println Hudson.instance.getItem(env.JOB_NAME).definition.scm.userRemoteConfigs[0].url
Jenkins will complain about security so you must approve signatures in Manage Jenkins -> In-process Script Approval
Upvotes: 1