Email: info@zenconix.com

Understand build triggers in Jenkins

Published on: 12/29/20 3:05 AM

Category:DevOps Jenkins Tags: , , ,

Hello All,

Before getting started to understand build triggers in Jenkins, it is highly recommended to see previous post about Jenkins on our blog so that you will have good idea about Jenkins and will help to understand this post.

Lets get started, in previous post, we have seen how to create simple job in Jenkins

Create simple jobs in Jenkins

Now, in this post we will try to understand build triggers in Jenkins.

We have different type of build triggers available in Jenkins, we will see them one by one.

Trigger build Remotely

Quickly click on New Items from left side menu and create freestyle project there.

Next, scroll down to build trigger and select “Trigger build remotely”

With this, you need to enter Authentication token, make sure it is more complex.

Now we have URLs to build our jobs

JENKINS_URL/job/TriggerBuildRemotely/build?token=TOKEN_NAME

In our case, it would be

http://localhost:8080/job/TriggerBuildRemotely/build?token=Token$1234

OR

we have another URL

/buildWithParameters?token=TOKEN_NAME

In our case, it would be

http://localhost:8080//buildWithParameters?token=Token$1234

Now save the jobs and our job is ready

Now go to browser and hit URL as below.

http://localhost:8080/job/TriggerBuildRemotely/build?token=Token$1234

it will build our job, which we can see in history.

Also we can see console output as below.

Build After other projects are built

For this case, lets quickly create two new projects, ProjectOne and ProjectTwo

here I have created two new projects

also added Execute windows batch commands to them as echo ProjectOne and echo ProjectTwo respectively.

Now we need to build ProjectTwo once build of ProjectOne is finished.

Go to ProjectTwo and click on Configure

In that scroll down to Build Triggers and select “Build after other projects are built”

In Project to watch : enter “ProjectOne”

Note: we also can mention names of multiple projects there.

and select appropriate options below.

Save the project and build ProjectOne, once ProjectOne’s build is completed, it should automatically trigger the build run for ProjectTwo

I go to ProjectOne and from left side menu, hit on Build Now button.

And once its build has finished, we can see ProjectTwo’s build will start and in below image, can see it has finished successfully.

Build Periodically

Build periodically means, it will build the project in mentioned periodic time, example, if we setup to build the project every morning, it will build the project every morning at mentioned time or we can setup once in month or once in year etc.

Lets create new freestyle project to trigger it periodically.

Scroll down to Build Trigger option, select “Build Periodically”

In schedule, we can write the frequency of build to execute. If you click on Help icon, you can see detail information about how to setup schedule for job.

For now. I have setup per minute job, to that it will execute on every minute.

To setup per minute schedule, just write down * * * * * all starts separated by white space or tab

Save the Project and check out the history, it will execute every minute.

In upcoming post we will take a look on Poll SCM build trigger.


Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Send email by Jenkins

In this post, we are going to take a look on how to setup basic email configuration for Jenkins and send mail if build job fails. First and formost, make sure, you have installed some email plugin so that it will allow you to configure email setup. You can install any email extension plugin example […]

Create Parameterized job in Jenkins

In last post, we have seen how to create simple job in Jenkins. Now, in this post we will take a look on how can we create parameterized job in Jenkins. Lets start with creating new project. Click on new item, and create freestyle project as below and hit OK button From general setting, select […]

Create simple jobs in Jenkins

In this post, we are going to see how to create jobs in Jenkins. If you are coming here at first time, I recommend to go to my previous post where we have explained about how to have initial setup for Jenkins in link below. Now, lets get started to create job in Jenkins Give […]