Pipeline: Hos to test them locally

2,111 views
Skip to first unread message

Victor Martinez

unread,
Dec 9, 2016, 2:20:46 AM12/9/16
to Jenkins Users
Hi there,

Just wondering if there is any new supported feature of testing Jenkinsfile, aka pipelines, locally, if so, where can i find some examples/docs? I want to get rid of the manual and tedious process of pushing changes to my repo then look at the jebkibs job andsee whether it does what i coded. I'd like to speed up my development with lets say some TDD. If no, will it be supported in the near future? Or it doesnt make sense?

Thanks guys

Michael Kobit

unread,
Dec 10, 2016, 1:00:10 PM12/10/16
to Jenkins Users
You can use the "Replay" option, which might help you iterate a little bit faster. There isn't really a good way to test and validate that your pipeline is correct other than just running it.

https://issues.jenkins-ci.org/browse/JENKINS-33925 is open for a test framework for Jenkinsfile.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/c6122b07-85f3-407b-8e81-ae23651e0b27%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Victor Martinez

unread,
Dec 11, 2016, 6:25:04 AM12/11/16
to Jenkins Users
I'll follow that jira ticket then. Thanks Michael

Peter McNab

unread,
Dec 12, 2016, 12:19:40 PM12/12/16
to jenkins...@googlegroups.com
The (far from perfect) method we've been using is to use a "testing" pipeline job.  Rather than fetching the project from source, it is an explicit script that uses a "load" to load in the "real" pipeline script from my development environment (which is available via NFS).

sourcepath = <PATH TO MY SRC DIR>'
node('master') {
  load "${sourcepath}/Jenkinsfile"
}

That allows me to just save locally and run the job.

Even better, I can then run the job using the jenkins-cli.jar and see the output in my shell which removes the need to interact with the jenkins UI altogether.

java -jar jenkins-cli.jar -s $JENKINS_URL build $JOB_NAME -s -v

Of course you have to be disciplined about checking in WIP and making sure that all files your pipeline is trying to use checked in eventually, and there are some cases where the above method acts a little differently than when pulling from SCM.  Also be sure to check "Use Groovy Sandbox" since pipeline scripts coming from SCM have that set. 

Pete

For more options, visit https://groups.google.com/d/optout.


-- 
Peter McNab | Engineering Tools Tech Lead
T: +1 510-473-3124 | M: +1 408-203-7114
http://www.perforce.com

Torsten Reinhard

unread,
Dec 25, 2016, 6:04:48 AM12/25/16
to Jenkins Users
Hi,

we were also wondering why there´s that pipeline-as-code approach available and strongly recommended everywhere - without any traditional support (automated tests) of developing clean code for it.

So we worked around that by doing the following:
- we have a Test Jenkins instance running where the pipeline code is tested first. pushes or released versions only go to productive Jenkins if well tested
- we "mocked" the pipeline DSL methods which enables us to at least do some basic groovy syntax and compilation tests. So far, Mockito, JUnit, Spock helps us a little.
- we developed some simple "integration-test" pipelines where we can test the pipeline code first - before testing or using it with real-life projects.

It´s currently a time-consuming and sometimes frustrating process to get things running - but we are looking forward to a lot of improvements coming soon.

Good luck,

Torsten
Reply all
Reply to author
Forward
0 new messages