How to run Jenkins Groovy scripts directly from Intellij or Eclipse How to run Jenkins Groovy scripts directly from Intellij or Eclipse jenkins jenkins

How to run Jenkins Groovy scripts directly from Intellij or Eclipse


I would suggest to treat your pipeline code like some other code in IT. What are you doing now could be called "manual integration tests" because you are making your code changes and check how that code integrate with other components (like shell commands, jenkins plugins, etc.) on jenkins - this development loop is long and not efficient. So my proposition for you is to write simple unit tests using this framework:https://github.com/jenkinsci/JenkinsPipelineUnitSo you can test your pipelines on your machine without any interaction with jenkins.

If you think that it's not proper way for you I would suggest to mix using this plugin for running jobs directly from IntelliJ: https://github.com/programisci/jenkins-control-plugin/and of course IntelliJ git integration to commit your changes to repository.


For executing from the IDE, an option is to create some automation around using the Jenkins CLI. You should be able to see the CLI commands at http://your-jenkins-url/cli.

java -jar jenkins-cli.jar -s https://jenkins.physiq.zone/ replay-pipeline JOB [-n (--number) BUILD#] [-s (--script) SCRIPT]

Replay a Pipeline build with edited script taken from standard input

JOB : Name of the job to replay.

-n (--number) BUILD# : Build to replay, if not the last.

-s (--script) SCRIPT : Name of script to edit, such as Script3, if not the main Jenkinsfile.

For example, in IntelliJ you could use a Run Configuration that:

  • Downloads the CLI JAR
  • Executes it with the path to the local file with certain parameters

You can also write a script, Gradle build, or something else that wires into the IDE to pull the CLI JAR and execute a job with your local pipeline code.

For testing you may want to use https://github.com/jenkinsci/JenkinsPipelineUnit as already brought up, or a Gradle plugin that I maintain at https://github.com/mkobit/jenkins-pipeline-shared-libraries-gradle-plugin which uses the previously mentioned library for unit testing and the jenkinsci/jenkins-test-harness for integration testing.