What is a job in jenkins?

Job is a fundamental unit of executable task on Jenkins, you can define you job to perform any task that you need. The jobs can be used to compile, test and deploy codes or practically anything you would want to. Jenkins come bundled with some of the plugins like java, ant, maven which help you perform your most common task of managing a project. However, Jenkins is not limited to managing only java project, it can be used to build any project in any language or framework you can think of.

In its very raw form, job offers you an ability to execute any command you would like to at a known interval or at an event.

Creating job in Jenkins using UI?

You can create a new job by clicking new item in Jenkins.

Once you click the new item link, you would be given option to choose various types of job which are supported by Jenkins.

There are two most common ways you can create a job which is using a freestyle project or pipeline. We will be using freestyle project in this article, but we will briefly talk about other options here.

What is Jenkins freestyle project?

As the name suggest, it’s a free style project which allows you to perform any task you want using a configuration which you would specify in the next step. Any plugin you use, would add more configuration which may allow you to perform steps, like if you want to build a docker container or trigger the build when a pull request is raised.

Freestyle project have a limitation that they usually work on only one repository and build one project. If you have to build multiple project or do multiple task like build, deploy, run acceptance test, you would end up having multiple freestyle jobs which would be tied up using downstream job.

What is Jenkins Pipeline

Pipeline are exactly opposite of a freestyle project, i.e instead of config based, pipeline is a groovy script which gets executed by Jenkins.You can code anything you can think of in a pipeline. Jenkins has its own library of common task which you can use in your pipeline. Pipelines are very powerful tool, but they usually have learning curve.

I would really recommend using pipelines if you want multistep execution, i.e. in a single pipeline you can take your code from version control, system, deploy it on test environment, run the acceptance test, publish results, merge branches and deploy to production, which is a complete CI/CD capability.

In a freestyle project, you would have multiple jobs which would be tied up together using downstream job.

What is multi-configuration project in Jenkins?

Multi configuration projects are special type of freestyle project for situations where you need to build multiple versions based on a config. For example if you need to run test on 3 different browsers or build for more than one operating system.

What is Github organisation in Jenkins?

Github organization is a Jenkins feature where once you connect your github account to Jenkins, it will scan all project and all branches and pull them into Jenkins as jobs. This feature relies on the fact that all the project and branches would have a script named Jenkinsfile in source containing pipeline code.

What is multibranch pipeline in Jenkins?

Multibranch pipeline in Jenkins is similar to github organization. You can add any github repository to Jenkins and it will scan all branches for a Jenkinsfile file in the source, and pull them as a job in Jenkins. This also relies on the fact that you would add pipeline code in Jenkinsfile.

Jenkins job configuration

Lets take a look at the configuration for freestyle project which you would need to specify to create a job.

Source code management

Jenkins support Git and Subversion out of the box as version control system but other version control system can be added to Jenkins via plugins. In this case we would be using Git as VCS. You can add the repository url and specify the branch to be checked out, you can add customization this behavior by looking at the options in additional behavior option below.

Build triggers

Jenkins support multiple way you can trigger the build, the most common way is to build periodically i.e. nightly builds or weekend long testing. Poll SCM would periodically poll the VCS, if there is a code change detected, it would trigger the build otherwise the build is not triggered. You can define a dependent build using “Build after other project are built” i.e. run acceptance test after the deployment is done. Github pull request builder would trigger the build every time one of the developer raises a pull request in github, you would need to specify additional configuration for github pull request

Build Steps

Jenkins support Shell, Ant, maven and gradle to build your project, once you choose your build tool, you can specify additional parameter about how to build the code. In this case we would be specifying what maven command we would like to execute. You can add multiple build steps which would be executed sequentially, and build would fail if any of these steps fails to execute.  This gives you flexibility to do practically anything and pre, post and during build phase. Some of the examples could be, to move some files, or generate some of code before compilation or change maven profile for build steps.

Post Build actions

In the post build step, you can choose action which you want to be done after a successful build. Some of the common ones are already available in the options.

How to copy jobs in Jenkins

If you have lots of repository and lots of code to be built, then adding all the configuration may be chore. A relatively easier way would be to clone the existing job into a new one using the copy from option when creating a new job.

How to delete job in Jenkins

Jenkins does not give you a delete button to delete your job anywhere in the UI. The secret trick to delete the job is to append /delete to the url of the job. So if my job url is http://localhost:8080/job/test/, then the delete url for this job would be http://localhost:8080/job/test/delete once you hit the url in browser you would be promoted with a confirmation to delete the job.



There are currently no comments.