[英]Can I create new jobs in a Jenkins pipeline script
I am wondering if it is possible to create new Jenkins build-jobs from within the pipeline groovy script. 我想知道是否有可能从管道groovy脚本中创建新的Jenkins构建作业。 I know that it is possible to start existing jobs, but I would also like to create new jobs in the script and then start them.
我知道可以启动现有作业,但我还想在脚本中创建新作业然后启动它们。
This would allow me to create a "job-graph" in my script. 这将允许我在我的脚本中创建一个“作业图”。 With job-graph I mean a collection of build-jobs that may rely on each others results and the graph determines which jobs can be run in parallel.
对于作业图,我的意思是可以依赖于彼此结果的构建作业集合,图表确定哪些作业可以并行运行。 Something like
就像是
/- WindowsBuild---------- WindowsRunTests -------------\
/ \
JobRoot --- LinuxBuild------------ LinuxRunTests ----------------/-- AllDone
\ \ /
\ \- LinuxRunDynamicAnalysis ----/
\- StaticCodeAnalysis -------------------------------/
Before I switched to the Pipeline job I did this by manually creating the jobs and setting their dependencies. 在我切换到Pipeline作业之前,我通过手动创建作业并设置其依赖项来完成此操作。 Now I would like to create the necessary jobs in the script.
现在我想在脚本中创建必要的工作。
With the current model for parallalism in the jenkins pipeline I have a build-stage, a test-stage, etc but the stages slow down the overall execution because for example the WindowsRunTests-step will not be started before all build-steps on all platforms have finished although it only needs the results from the WindowsBuild-step. 在jenkins管道中使用当前的parallalism模型我有一个构建阶段,一个测试阶段等,但这些阶段会降低整体执行速度,因为例如在所有平台上的所有构建步骤之前都不会启动WindowsRunTests步骤已完成虽然它只需要WindowsBuild步骤的结果。
It may also improve visualizing the pipeline and separating the console ouput which gets mixed together with the parallel()
command. 它还可以改进管道的可视化并将使用
parallel()
命令混合在一起的控制台输出分开。
I don't know exactly if it can help you but you can do it with a workaround. 我不确切知道它是否可以帮到你,但你可以通过一种解决方法来实现。 You can run a python script and within that script you can create new jobs by copying an existing job template:
您可以运行python脚本,在该脚本中,您可以通过复制现有作业模板来创建新作业:
jen_conn = connect_to_jenkins(jenkins_url, jenkins_user, jenkins_password)
jen_conn.copy_job('copy-job-dev', jenkins_job_name)
With the function as below: 具有以下功能:
def connect_to_jenkins(jenkins_url, jenkins_user, jenkins_password):
server = jenkins.Jenkins(jenkins_url, username=jenkins_user, password=jenkins_password)
try:
user = server.get_whoami()
except BaseException as error:
print error
print "Could not connect to Jenkins."
exit()
return server
You would have to use the jenkins plugin for python. 您将不得不使用python的jenkins插件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.