Trigger build of Jenkins from Remote or AWS UserData

Trigger build of Jenkins from Remote or AWS UserData

I am working currently on a project which required automatic build triggering from remote to run my ansible-playbook which will configure our Instance launching under Auto Scaling.

We can do it using many ways but the easiest way to achieve it which I have used, I just want to share with you all.

Let’s start by configuring our Jenkins server first.

Requirements:

  1. Jenkins Server
  2. Jenkins Authentication Keys

Why Jenkins Authentication Keys?

Jenkins Authentication Keys required to authenticate yourself while requesting to trigger the build through Jenkins API from remote.

Step 1:

Go to Manage Jenkins then click on the label shown below.

askops.in

Step 2:

Click on the user setting as shown below.

Step 3:

Now click on Add new Token.

Once you will click there It will generate the token for you, make sure to keep it safe else you need to generate it again as soon as you will leave the page.

Step 4:

Now let’s Create the test job “Auto-trigger-test” with the below configuration.

My requirements are of creating a parameterized build job. If your’s too then follow the below steps.

Now don’t get confused in Authorization token, put whatever you want instead of “build”, but make sure to remember, you will require this in the below step.

Save and apply the configuration.

Step 5:

Now we will use the curl command to call the API of Jenkins which will trigger our build.

  1. <username> This will be replaced by the username you use to login to the Jenkins server.
  2. <token> The token you have generated above.
  3. <jenkins_domain_url> this will be replaced by your Jenkins domain name or URL
  4. ** build: This can be replaced by whatever you have given above.

Now for securing our API token and calling it as an ENV Parameter is a pending task on which I am working, didn’t actually get time.

Maybe I will use KMS and SSM of AWS and will write a script that will fetch the token and pass it there inside the “curl” command as a variable.

Askops
Askops
Developer: Nikhil raj
Price: Free

Leave a Reply