-
Improvement
-
Resolution: Unresolved
-
Minor
-
None
I'm trying to use the declarative-linter to lint declarative pipelines in shared libraries, as described in https://jenkins.io/doc/book/pipeline/shared-libraries/#defining-declarative-pipelines
It works - if I try linting the following,
def call(String name) { pipeline { agent { label 'Default' } stages { stage('Build') { steps { sh 'I am a bad step directive' 'very bad' sh('echo ${name}') } } } } }
it correctly fails, saying -
WorkflowScript: 8: Expected a step @ line 8, column 21. sh 'I am a bad step directive' 'very bad' ^
However, if I mistakenly forget to include an agent directive, like so -
def call(String name) { pipeline { // agent { label 'Default' } stages { stage('Build') { steps { sh 'I am a bad step directive' 'very bad' sh('echo ${name}') } } } } }
the linter just completes with an exit code of 0.
I believe this is a mistake - a declarative pipeline is invalid if it is missing the agent directive, and as using a declarative pipeline shared library provides no additional opportunity to specify this, it should also be invalid.
I've tracked this down to https://github.com/jenkinsci/pipeline-model-definition-plugin/blob/master/pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/ASTParserUtils.groovy#L495L496 where it explicitly ignores declarative pipelines that do not contain the agent or stages directive in shared libraries (according to the comment too).
I've also had a quick look at the users of that method and can't find any clues either. Can someone shed some light here?
I'm happy to propose the change, but I'm not sure it's correct.