Jenkins Declarative Pipeline Linter
A plugin to lint Jenkins declarative pipelines via the Jenkins CLI.
Getting Started
In order to use the Jenkins Declarative Pipeline Linter plugin you need to configure Jenkins to recognize your public key and set the jenkins-declarative-linter.url
, jenkins-declarative-linter.port
, and jenkins-declarative-linter.user
VSCode settings.
NOTE
If you are not using the standard ~/.ssh/id_rsa
key, set the jenkins-declarative-linter.key
setting to the path of your key file.
NOTE
You need to have your public key configured in the Jenkins instance you are using for validation. In order to configure your public key in Jenkins:
- Navigate to
https://<JENKINS_INSTANCE>/me/configure
.
- Locate 'SSH Public Keys' and add your public key.
Settings
The following settings can be set via the UI or the settings.json
file.
jenkins-declarative-linter.url
The URL to the Jenkins instance.
Required: true
Example
{
"jenkins-declarative-linter.url": "localhost"
}
jenkins-declarative-linter.port
The SSH port configured for the Jenkins instance.
Required: true
Example
{
"jenkins-declarative-linter.port": "2222"
}
jenkins-declarative-linter.user
The username for connecting to the Jenkins instance.
Required: true
Example
{
"jenkins-declarative-linter.user": "user1"
}
jenkins-declarative-linter.key
The path to the SSH key for connecting to the Jenkins instance.
Required: false
Example
{
"jenkins-declarative-linter.key": "/path/to/key"
}
Usage
To lint a declarative Jenkins pipeline script:
- Open the script in a text editor window.
- Enter
>Lint Jenkinsfile
in the command pallete.
- The results will appear in a
JDL
output view.
Output: Valid Script File Example
[INFO] Validating c:\tmp\jenkinsdev\jenkinsfiles\NAntDbTest.jenkinsfile
[INFO] Jenkinsfile successfully validated.
GIF
Output: Invalid Script File Example
[INFO] Validating c:\tmp\jenkinsdev\jenkinsfiles\NAntDbTest.jenkinsfile
[INFO] Errors encountered validating Jenkinsfile:
WorkflowScript: 22: Unknown stage section "script". Starting with version 0.5, steps in a stage must be in a ‘steps’ block. @ line 22, column 5.
stage('Execute NAnt DB Scripts') {
^
WorkflowScript: 22: Expected one of "steps", "stages", or "parallel" for stage "Execute NAnt DB Scripts" @ line 22, column 5.
stage('Execute NAnt DB Scripts') {
^
GIF
Attributions
Images