jenkinsfile example

jenkinsfile example

Jenkinsfile contain a pipeline configuration. Jenkins will look this file and based on the steps it will execute the build. below Jenkinsfile example are show how to use them. Jenkinsfile: and Pipelines  Together is a new concept. This file creates in your repo, which contains your pipeline configuration. Jenkins will look for this file in your branches and execute the build according to the stages defined in there. This is possible to have your pipeline configuration together with your project and under version control.

Pipeline Groovy

In CentOS and Linux Jenkinsfile placed  under the default folder (replace “onclick360” with the name of your job): /var/lib/jenkins/workspace/onclick360@script/Jenkinsfile

jenkinsfile example :-

1. Jenkinsfile for Hello World.
#!/usr/bin/env groovy
node {
echo 'Hello World'

2. Groovy variable into a string argument

#!/usr/bin/env groovy
node {
stage('Execute shell') {
var = "name"
sh "echo Hello ${var}"

3. Jenkinsfile Build and test a Maven project

# Jenkinsfile
# Maven project Build and test.
#!/usr/bin/env groovy

node { git url: '' def mvn = tool 'M3' sh "${mvn}/bin/mvn -B -Dmaven.test.failure.ignore verify" step([$class: 'JUnitResultArchiver', testResults: '**/target/foobar/TEST-*.xml']) }

4. Jenkinsfile Verify a Maven project.

# Jenkinsfile
# Maven project node
#!/usr/bin/env groovy
{ git url: '' def mvn = tool 'M3' sh "${mvn}/bin/mvn -B verify" }

5. Run build in parallel mode.

#!/usr/bin/env groovy
node ( 'slave1' ) {
parallel (
linux: {
sh './linux_script.bash -t linux_amd64'
windows: {
sh './windows_script.bash -t windows_amd64'


Jenkinsfile provides a number of immediate advantages:

  • Code audit and review on the pipeline.
  • Once Jenkinsfile tested for some build, it can be reusable to another project.
  • Jenkinsfile can be viewed and modify if needed by others members of projects.
  • All code use stage by stage process like Compile stage, Build stage, Deploy stage and testing stage and this all stage can automate at one place.
  • It uses Groovy language which is easy to understand and can do a lot of automation which may difficult if use Jenkins build GUI.
  • By using Groovy language we can use the simple syntax to use parallel branches for pipelines.

Hope you enjoy this Article.

You May Also Like

4 thoughts on “jenkinsfile example

  1. I’ve read several good stuff here. Certainly worth bookmarking for revisiting. I wonder how much effort you put to create such a great informative web site.

  2. Hello there, just became aware of your blog through Google, and found that it is truly informative. I’m gonna watch out for brussels. I’ll appreciate if you continue this in future. Lots of people will be benefited from your writing. Cheers!|

  3. Excellent post. I was checking continuously this blog and I am impressed! Extremely useful information specially the last part 🙂 I care for such info a lot. I was seeking this particular info for a long time. Thank you and best of luck.|

  4. I want to to thank you for this wonderful read!! I absolutely loved every little bit of it. I have you book-marked to look at new things you post…|

Leave a Reply

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