我试图从管道中自动创建Jenkins管道构建。
我有一个管道,它创建一个Bitbucket存储库,并向它提交一些代码,包括一个Jenkinsfile。
我需要向这个管道添加另一个步骤,然后为它创建管道构建,这将运行Jenkinsfile中的步骤。
我认为乔布斯DSL应该能够处理这个问题,但是我为它找到的文档非常稀少,我仍然不完全确定它是否可能或如何做到。
任何帮助都将不胜感激。我认为生成的管道构建只需要一个到存储库的链接,并被告知在那里运行Jenkinsfile?
发布于 2018-11-19 10:28:01
是的,作业DSL是您需要的用例。
编辑
pipeline {
agent {
label 'slave'
}
stages{
stage('stage'){
steps {
// some other steps
jobDsl scriptText: '''pipelineJob(\'new-job\') {
def repo = \'https://xxxxx@bitbucket.org/xxxx/dummyrepo.git\'
triggers {
scm(\'H/5 * * * *\')
}
definition {
cpsScm {
scm {
git {
remote {
url(repo)
credentials('bitbucket-jenkins-access')
}
branches(\'master\')
scriptPath(\'Jenkinsfile\')
extensions { }
}
}
}
}
}'''
}
}
}
}文档- https://jenkinsci.github.io/job-dsl-plugin/#path/pipelineJob-scm-git
发布于 2020-07-07 21:38:59
通过使用这个python库jenins-职业建设者,您可以轻松地从另一个管道或任何其他远程位置创建您期望的管道或自由样式的作业。
示例:
步骤-1
python3 -m venv .venv
source .venv/bin/activate
pip install --user jenkins-job-builder步骤-2
完成上述操作后,创建2个文件,一个文件名为config.ini,另一个文件名为job.yml。请注意-没有关于文件名的严格规则。这可以由你来决定。
config.ini文件包含的内容如下所示
[job_builder]
allow_duplicates = False
keep_descriptions = False
ignore_cache = True
recursive = False
update = all
[jenkins]
password = jenkins-password
query_plugins_info = False
url = http://jenkins-url.net
user = jenkins-username如果您正在创建一个管道作业,那么您的job.yml文件可以如下所示
- job:
name: pipeline01
display-name: 'pipeline01'
description: 'Do not edit this job through the web!'
project-type: pipeline
dsl: |
node(){
stage('hello') {
sh 'echo "Hellow World!"'
}
}步骤-3
在做了以上所有事情之后。调用以下命令
jenkins-jobs --conf config.ini update job.yml注-jenkins-作业命令只能在您遵循步骤-1的情况下才可用。
https://stackoverflow.com/questions/53372072
复制相似问题