且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何直接从Intellij或Eclipse运行Jenkins Groovy脚本

更新时间:2023-12-05 13:34:34

要在IDE中执行,可以选择使用Jenkins CLI创建一些自动化功能.您应该可以在 http://your-jenkins-url/cli 上看到CLI命令.

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/重播管道作业[-n(--number)BUILD#] [-s(--script)脚本]

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:要重播的作业的名称.

JOB : Name of the job to replay.

-n(--number)BUILD#:构建为重播,如果不是最后一个.

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

-s(--script)SCRIPT:要编辑的脚本名称,例如Script3(如果不是主Jenkins文件).

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

例如,在IntelliJ中,您可以使用

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

  • 下载CLI JAR
  • 使用带有某些参数的本地文件路径执行

您还可以编写脚本,Gradle构建或其他可以连接到IDE的东西,以提取CLI JAR并使用本地管道代码执行作业.

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.

对于测试,您可能需要使用 https://github.com/jenkinsci/JenkinsPipelineUnit 作为已经启动,或者我在 https://维护的Gradle插件中github.com/mkobit/jenkins-pipeline-shared-libraries-gradle-plugin ,它使用前面提到的库进行单元测试和

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.