[Jenkins] Setup Your Freestyle and Pipeline Jobs

Jie Liau
4 min readAug 1, 2021

--

Today I will go through how to setup your Freestyle and Pipeline jobs on Jenkins. If you still don’t have any idea on how to setup your Jenkins server. Here you are.

0x01 Freestyle Job

Freestyle job is the easy way to automate your build or testing jobs on Jenkins. On the Dashboard page, click New Item, name your item name and then choose Freestyle project and then click ok. At this time, you have to configure your freestyle project. In General section, you can config some basic information for this project as well as restrict this project only running on specific worker node. See below:

In the Source Code Management section, you could choose Git as your SCM and specify your Github repo and which branch you would like to run. You could also specify the credential if your repo is private. Please refer the following screenshot.

Jenkins has lots of build method you could choose, in my example, I use execute shell and specify the command I would like to run to build/automate my code. You also have Invoke Ant or Invoke Gradle script. Please see below screenshot.

After above configuration, go back to project and click build now. And you will see there is new project number shown up in the left-down corner. Click into that number, you could see the details of your build, like status and console output.

0x02 Pipeline Job

Jenkins also provides another way to run/automate your code, which is called Pipeline. You could just specify where your pipeline file locates and define different stages to do different things. Running current stage or not depends on previous one’s result. You can reference here to see how to write your first Jenkins file.

In the example here, I also start from clicking New Item and choose Pipeline at this time. And in the configuration of this project, I will put my Jenkins file on my Github repo here and choose Pipeline script from SCM. I will specify where my Github repo is and which branch I use. See below.

Please see my Jenkins file source code here.

This job will run on any available agent and I will define 2 environment variables, API and PASS, both are read from credentials setup on my Jenkins server.

And for the stage1, I will check-out my Github project into my Jenkins and then will go to stage2. In the stage2, I will execute bash ./example.sh stage1 and then go to stage3 to execute bash ./example.sh stage2. All the example source code is available on my personal Github repo below:

And then you could go back to Jenkins project page and click build now of this project.You will see the status is quite different from Freestyle project. See below:

So Above are 2 different popular ways to run/automate your code on JenKins. There is no preference to recommend. All depends on your present requirement. Hope you enjoy the article and find your way on Jenkins.

--

--

No responses yet