HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Validating custom Jenkinsfile

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
jenkinsfilecustomvalidating

Problem

Currently we're using 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.

Solution

As far as I see, there are two possible approaches, either by misusing reusing the Blue Ocean plugin or using the Groovy-based Jenkinsfile unit test tool.

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, 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 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.

Context

StackExchange DevOps Q#3238, answer score: 2

Revisions (0)

No revisions yet.