如何直接从Intellij或Eclipse运行Jenkins Groovy脚本 [英] How to run Jenkins Groovy scripts directly from Intellij or Eclipse
问题描述
我有一个Groovy存储库,其中包含我的Jenkins管道的Groovy代码.
I have a Groovy repository which contains my Jenkins pipeline's Groovy code.
当前,我正在IDE中进行更改,将其提交到存储库,转到Jenkins实例,手动触发Jenkins作业,并检查所有更改是否都有效.这需要很多时间.
Currently, I am making changes in an IDE, commiting them to the repository, going to the Jenkins instance, manually triggering a Jenkins job, and checking to see if all of the changes all working. This is taking a lot of time.
是否可以通过IDE本身完成所有这些操作?
Is there a way to do all of this from the IDE itself?
推荐答案
要在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.
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.
这篇关于如何直接从Intellij或Eclipse运行Jenkins Groovy脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!