0
votes

I have setup "Enable Artifactory trigger" on my jenkins job. The job gets triggered automatically whenever there is an update in the artifactory path. The trigger job output provides the artifact that triggered the build. What i need is to parse the artifact and use as an environment variable?

Jenkins console log of artifactory trigger job

The build was triggered by a change in Artifactory.
The artifact which triggered the build is: http://xxx.xxx.com/artifactory/api/storage/artifactory-snapshot/ABC/exp-abc-12-5-br/abc-12-5-99-015/up-image.tgz
[EnvInject] - Loading node environment variables.
Building remotely on slave in workspace /data/engit-private-jenkins/workspace/Tools/test_artifactory_trigger
[test_artifactory_trigger] $ /bin/sh -xe /tmp/jenkins6159521155154940953.sh
+ echo 'hello world'
hello world
Finished: SUCCESS

How do I access the http artifactory url in the above jenkins console log in the same job? I dont see it getting stored in the environment

1
I did some search and couldnt get the artifactory http url environment variable from the plugin. Ended coming up with a script to use the $BUILD_URL/consoleLog and parse the http url in it.Darshan
instead of parsing the log file. you can set a global variable named artifactory_url and access it directly. If you are using pipeline model then the it can be accessed via groovy as wellerror404
when you say artifactory_url, do you mean the repo url? The repo url keeps changing as the artifacts are placed in different paths xxx.xxx.com/artifactory/api/storage/artifactory-snapshot/ABC/… next one could be xxx.xxx.com/artifactory/api/storage/artifactory-snapshot/ABC/… and so on. I like the groovy thing you talk about. Can you provide some pointers to it?Darshan
Ohk..I thought you just need the artifactory_url i.e the fixed part for some stuff. Let me share some link with you based on the use case. I have not used the Enable artifactory plugin I will check if the declarative syntax supports that.error404
This indeed seems like a useful functionality. We will add it to the Jenkins Artifactory Plugin features backlog.Eyal Ben Moshe

1 Answers

0
votes

We can get the URL of the file in Artifactory that triggered the job using :

environment {
RT_TRIGGER_URL = "${currentBuild.getBuildCauses('org.jfrog.hudson.trigger.ArtifactoryCause')[0]?.url}"
}

Build trigger documentation link