Answers: <p>As far as I see, there are two possible approaches, either by <del>misusing</del> reusing the <a href="https://stackoverflow.com/a/45330705/6783666">Blue Ocean plugin</a> or using the <a href="https://github.com/jenkinsci/JenkinsPipelineUnit" rel="nofollow noreferrer">Groovy-based Jenkinsfile unit test tool</a>.</p>
  
  <p>The groovy approach might be a bit of overhead, since it is not a client-side Javascript verification. An idea would be to run an async task, server side that tests the code the developer provides and returns the results to the client. You mentioned that the shared libraries are not being parsed properly. This might be resolvable through the use of mock Jenkins commands and objects. This might also avoid the security risk which is created through <a href="https://jenkins.io/doc/book/pipeline/shared-libraries/" rel="nofollow noreferrer">shared libraries</a>, which requires users having push rights.</p>
  
  <p>The client-side solution might be to provide a playground via the Blue Ocean plugin or directly present the Jenkinsfile that has been created <a href="https://stackoverflow.com/a/43640430/6783666">via a redirect</a> of the Jenkinsfile to Blue Ocean.</p>
  
  <p>All in all, there is no straight forward JS library solution to your problem, as far as I can tell.</p>
  
Answers: CC BY-SA 3.0
Answers: 2018-02-06T15:15:09.923Z
Answers: After some tinkering with Jenkins I have decided to use JenkinsRule instance inside of a test case and also use LibraryRetriever to load required custom libraries. This approach allows me to do some assertions in build logs as well as verify build statuses. However problem is external dependencies - git repos and slack notifications. So currently I'm still trying to come up with more lightweight solution. Will post updates afterwards.
Answers: zrks
Answers: CC BY-SA 3.0
Answers: 2018-02-06T16:25:24.130Z
Answers: Cool, you could also post your own answer and then accept it
Answers: Moritz
Answers: CC BY-SA 3.0
Answers: 2018-02-01T11:54:04.150Z
Answers: 2018-02-01T11:54:04.150Z
Answers: Moritz
Body: <p>Currently we're using <a href="https://jenkins.io/doc/book/pipeline/shared-libraries/" rel="nofollow noreferrer" title="Jenkins shared libraries">Jenkins shared libraries</a> which we're planning to use with custom Jenkinsfiles.
  Idea here is that developers should be able to manage those custom Jenkinsfiles without any additional help from DevOps team.</p>
  
  <p>In order to implement this feature I need some way how to validate this custom Jenkinsfile.</p>
  
  <p>Even if I have running Jenkins instance with configured shared libraries post to /pipeline-model-converter/validate wont lint my Jenkinsfile correctly as it wont load my custom libraries.</p>
  
  <p>Is there a convenient way how to check custom Jenkinsfile before actually executing it on running Jenkins instance? e.g., checking if method names in Jenkinsfile are correctly written.</p>
  
Tags: <testing><jenkinsfile>
Title: Validating custom Jenkinsfile
UserDisplayName: zrks
ThreadText: # Validating custom Jenkinsfile
  
  (Asked by: username_0 on 2018-02-01)
  
  Currently we're using [Jenkins shared libraries](https://jenkins.io/doc/book/pipeline/shared-libraries/ "Jenkins shared libraries") which we're planning to use with custom Jenkinsfiles.
  Idea here is that developers should be able to manage those custom Jenkinsfiles without any additional help from DevOps team.
  
  In order to implement this feature I need some way how to validate this custom Jenkinsfile.
  
  Even if I have running Jenkins instance with configured shared libraries post to /pipeline-model-converter/validate wont lint my Jenkinsfile correctly as it wont load my custom libraries.
  
  Is there a convenient way how to check custom Jenkinsfile before actually executing it on running Jenkins instance? e.g., checking if method names in Jenkinsfile are correctly written.
  
  **Tags:** testing, jenkinsfile
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-02-01. Score: 2
  
  As far as I see, there are two possible approaches, either by ~~misusing~~ reusing the [Blue Ocean plugin](https://stackoverflow.com/a/45330705/6783666) or using the [Groovy-based Jenkinsfile unit test tool](https://github.com/jenkinsci/JenkinsPipelineUnit).
  
  The groovy approach might be a bit of overhead, since it is not a client-side Javascript verification. An idea would be to run an async task, server side that tests the code the developer provides and returns the results to the client. You mentioned that the shared libraries are not being parsed properly. This might be resolvable through the use of mock Jenkins commands and objects. This might also avoid the security risk which is created through [shared libraries](https://jenkins.io/doc/book/pipeline/shared-libraries/), which requires users having push rights.
  
  The client-side solution might be to provide a playground via the Blue Ocean plugin or directly present the Jenkinsfile that has been created [via a redirect](https://stackoverflow.com/a/43640430/6783666) of the Jenkinsfile to Blue Ocean.
  
  All in all, there is no straight forward JS library solution to your problem, as far as I can tell.
  
  > **Comments:**
  > **username_0**: After some tinkering with Jenkins I have decided to use JenkinsRule instance inside of a test case and also use LibraryRetriever to load required custom libraries. This approach allows me to do some assertions in build logs as well as verify build statuses. However problem is external dependencies - git repos and slack notifications. So currently I'm still trying to come up with more lightweight solution. Will post updates afterwards.  
  > **username_1**: Cool, you could also post your own answer and then accept it  
  
  ---
  
  