0

I aiming to write a Perl script in a Unix environment which triggers a Jenkins build/job by passing the URL for the Jenkins master and other parameters. How could this be done?

Here are some detailed questions I had:

  • What Perl libraries would I need?
  • What functions in Perl are needed?
  • How can I pass other build parameters to Jenkins from the script?
  • How do I get the results back from Jenkins?

1 Answer 1

3

You would normally need the LWP module and maybe its sub modules. Here's an article on how you'd use it:

I am normally the person who will say "Don't use system when you can use a Perl solution".

However, I will make an exception in this case since it is way easier just to make that one system call to the wget command:

system qq(wget -q $build_trigger_url);

How can to pass other build parameters to Jenkins from the script?

To pass parameters to the Jenkins build will involve either setting environment variables by modifying the %ENV hash, or by modifying the URL to include these parameters (via a GET request). Different plugins and configurations require different ways of doing this.

If your build machine is a Windows system, you can download the wget command.

How do I get the results back from Jenkins?

Jenkins has a built-in RESTful API. Just click the REST API links that are on the bottom of each page. You can use the REST::Client module to make REST calls, but you can also just use system calls to wget too.

The RESTful API will return data in either JSON or XML format. You should get a JSON or XML module to help read this data. Sometimes, the RESTful API will return plain text like when getting the latest build number or timestamp.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.