-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Minor
-
Component/s: pipeline-model-definition-plugin
-
None
-
Environment:pipeline-model-definition-plugin version 1.9.1
Jenkins version 2.303.1 (LTS)
I am using https://www.jenkins.io/doc/pipeline/steps/pipeline-model-definition/#validatedeclarativepipeline-validate-a-file-containing-a-declarative-pipeline to validate a declarative Jenkinsfile pipeline, but when I use this step it in a declarative pipeline to validate a known-incorrect pipeline file it doesn't fail the build.
pipeline {
agent any
stages {
stage('Lint') {
steps {
// valid Jenkinsfile
validateDeclarativePipeline path: 'test_pipelines/pipeline1/Jenkinsfile'
// Jenkinsfile with syntax error
validateDeclarativePipeline path: 'test_pipelines/pipeline2/Jenkinsfile'
// valid Jenkinsfile
validateDeclarativePipeline path: 'test_pipelines/pipeline3/Jenkinsfile'
}
}
}
}
This shows the following messages in the build log, but doesn't fail the build.
[2021-08-30T06:39:31.958Z] Error(s) validating Declarative Pipeline file 'test_pipelines/pipeline2/Jenkinsfile' - org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: [2021-08-30T06:39:31.958Z] WorkflowScript: 95: expecting '}', found '' @ line 95, column 1. [2021-08-30T06:39:31.958Z] 1 error [2021-08-30T06:39:31.958Z]
I can see that other plugins raise an exception instead of returning a status code, so that Jenkins can fail the build when the step fails. Would it be possible to change validateDeclarativePipeline to raise an exception so that a validation failure will fail the build?
Am I missing something in how this should be used? I'm guessing it is possible to capture the return value and throw an exception inside a `script{}` block but I thought it would be easier and clearer to be able to not need all the extra scripted pipeline syntax around the step.