0

I've been looking and so far been unable to find a way of validating/linting my Jenkinsfile. At least not by using tox, pycharm or another way outside of visual code for example (I did saw some examples of that, more or less).

Does anyone know of a way to do this? I would like to perform some simple checks, like:

  • return a warning if an environment variable inside the file is used but isn't declared (so I know I have to check if it is set on server level, for example).
  • Creating some custom checks would be a huge plus: e.g. if strings, without variables, use single quotes instead of double.
Erik van de Ven
  • 4,747
  • 6
  • 38
  • 80

1 Answers1

0

Jenkins can validate, or "lint", a Declarative Pipeline from the command line before actually running it. This can be done using a Jenkins CLI command.

Linting via the CLI with SSH
# ssh (Jenkins CLI)
# JENKINS_SSHD_PORT=[sshd port on controller]
# JENKINS_HOSTNAME=[Jenkins controller hostname]
ssh -p $JENKINS_SSHD_PORT $JENKINS_HOSTNAME declarative-linter < Jenkinsfile

More info available at : Linter
Additional reference: Validate Jenkinsfile

Altaf
  • 2,838
  • 1
  • 16
  • 8