0

I have a Jenkins Pipeline script being used to deploy lambdas. Right now the user passes the parameters to the job to kick it off. I want to automate the job a bit more and create a process where the job triggers and the parameters are passed via a JSON file to kick off the job.

I'm not clear on how to proceed I've seen that maybe JsonSlurper could be used, but not sure if that is the ideal solution for the process.

Does anyone have a good solution that I could implement?

2 Answers 2

1

I would recommend the GenericWebhook Plugin.

You can define a token and then use a POST request to trigger the job with any JSON you need. The plugin will take care of triggering the job and even unpacking variables from the JSON if you want it to.

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

Comments

0

Might not be the best solution, but it's the one I use extensively. You can read in a JSON file like so..

node() { stage("Read JSON") { // This has to be done within a node() construct myObj = readJSON file: '/opt/app/jenkins/userContent/test.json' } } 

Here's a simple JSON file to test with..

{ "Hosts": [ { "Hostname": "host1.foobar.com", "Purpose": "Web Server" }, { "Hostname": "host2.foobar.com", "Purpose": "DB Server" }, { "Hostname": "host3.foobar.com", "Purpose": "App Server" } ] } 

You can reference it like so..

for (int hostnum=0; hostnum < myObj.Hosts.size(); hostnum++) { println "Hostname: " + myObj.Hosts[hostnum].Hostname println "Purpose: " + myObj.Hosts[hostnum].Purpose } 

From the build log..

Hostname: host1.foobar.com [Pipeline] echo Purpose: Web Server [Pipeline] echo Hostname: host2.foobar.com [Pipeline] echo Purpose: DB Server [Pipeline] echo Hostname: host3.foobar.com [Pipeline] echo Purpose: App Server 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.