A Jenkinsfile linter CLI saving time linting Jenkinsfiles by only typing 1 argument in the command line.
1.Credentials entered one time only
2.Short commands to type
3.Validate Jenkinsfiles through the Jenkins Client of your server
4.Masked credentials
Jklint can be installed through Pypi or a clone of the repository.
The easiest option to setup Jklint is to install the pip package and run it into a virtual environment.
python3 -m venv <virtual-environment-name>
Platform |
Shell |
Command to activate virtual environment |
---|---|---|
POSIX |
bash/zsh |
|
fish |
|
|
csh/tcsh |
|
|
PowerShell |
|
|
Windows |
cmd.exe |
|
PowerShell |
|
python3 pip install jklint
git clone https://github.com/aissa-laribi/jklint
python3 -m venv <virtual-environment-name>
Platform |
Shell |
Command to activate virtual environment |
---|---|---|
POSIX |
bash/zsh |
|
fish |
|
|
csh/tcsh |
|
|
PowerShell |
|
|
Windows |
cmd.exe |
|
PowerShell |
|
pip install -e .
It's recommended to run jklint from a virtual environment, this way the credentials and the Jenkins client will not be found in the repository. Only the Jenkinsfile should be in the repository.
1.Configure jklint
jklint config
If you work with VS Code and your OS is a POSIX OS, an .env file should open. Otherwise, find the .env file in your current directory(that should your virtual environment directory)
Replace the values with yours and save the file.
2.Validate the file
jklint go
It will download the Jenkins client from your Jenkins url. Then, it will proceed to the validation of the Jenkinsfile
If the credentials and the syntax of the Jenkinsfile are correct it should return:
Jenkins-client found
CompletedProcess(args=['java', '-jar', 'jenkins-cli.jar', '-s', 'jenkins-url', '-webSocket', '-auth', 'user', 'declarative-linter'], returncode=0, stdout='Jenkinsfile successfully validated.\n', stderr='')
And your 'user' and 'jenkins-url' details will stay hidden.