Running a Jenkins job from a shell script

964 views
Skip to first unread message

Alan Evangelista

unread,
Mar 1, 2016, 9:35:30 AM3/1/16
to jenkins...@googlegroups.com
I want to execute a Jenkins job run from a script, which is itself cloned from a git repo and called
in a shell build step by another Jenkins job. I need a Jenkins user and Jenkins user API token to run
a Jenkins job via its HTTP API. Is it possible to access the Jenkins user and user API token in the
script
mentioned above? I thought they would be available via shell environment variable, but it seems it
is not.

ps: I do not want to use Jenkins UI to setup the first Jenkins Job execution from the second.

Warren Postma

unread,
Mar 1, 2016, 9:51:33 AM3/1/16
to Jenkins Users, ala...@linux.vnet.ibm.com
Why don't you have your script execute some HTTP action with CURL which might trigger Jenkins?

W


On Tuesday, March 1, 2016 at 9:35:30 AM UTC-5, Alan Evangelista wrote:

Alan Evangelista

unread,
Mar 1, 2016, 9:13:38 PM3/1/16
to jenkins...@googlegroups.com
I do not need help in how to call the HTTP API. Triggering a Jenkins job requires the Jenkins API token;
my question is to how to have this Jenkins API token without hardcoding it in the script. The script
is in a public git repo and I dont want the Jenkins API token available to everyone.

As Jenkins user and user API token are not available via Jenkins env variables, the solution I found is
to put this data in a file (always in same path) in each Jenkins slave and the script opens the file
to get the data.


Regards,
Alan Evangelista

Michael Giroux

unread,
Mar 1, 2016, 10:16:04 PM3/1/16
to Jenkins Users, ala...@linux.vnet.ibm.com
If you are referring to the authtoken from build triggers, you could retrieve it using the jenkins cli to retrieve the config.xml for the job and extract the authToken element.

 <jdk>(System)</jdk>

  <authToken>xxxyyy</authToken>

  <triggers/>

  <concurrentBuild>false</concurrentBuild>

Reply all
Reply to author
Forward
0 new messages