我想通过Job DSL生成基于管道插件的作业,它包含在Jenkins签出的git存储库中。
然而,我认为在Job DSL脚本中将管道脚本作为带引号的字符串并不是很好。所以我想将它们读入一个字符串,并将其传递给script()函数:
definition {
cps {
sandbox()
script( new File('Pipeline.groovy').text )
}
}
}我必须将Pipeline.groovy放在哪里才能正常工作?我试着把它放在我的DSL脚本旁边,也放在我的DSL源代码的resources/文件夹中。但是Jenkins总是抛出一个"file not found“。
发布于 2017-08-16 01:43:48
你试过readFileFromWorkspace()吗?它应该能够找到你从git签出的文件。
发布于 2017-08-29 10:52:20
引用Job DSL pipelineJob:https://jenkinsci.github.io/job-dsl-plugin/#path/pipelineJob,并在http://job-dsl.herokuapp.com/上对其进行修改以查看生成的配置。
下面的job DSL创建了一个管道作业,它从Jenkinsfile中拉出实际的作业:
pipelineJob('DSL_Pipeline') {
def repo = 'https://github.com/path/to/your/repo.git'
triggers {
scm('H/5 * * * *')
}
description("Pipeline for $repo")
definition {
cpsScm {
scm {
git {
remote { url(repo) }
branches('master', '**/feature*')
scriptPath('misc/Jenkinsfile.v2')
extensions { } // required as otherwise it may try to tag the repo, which you may not want
}
// the single line below also works, but it
// only covers the 'master' branch and may not give you
// enough control.
// git(repo, 'master', { node -> node / 'extensions' << '' } )
}
}
}
}您/您的Jenkins管理员可能希望将Jenkins作业创建与实际作业定义分开。这在我看来是明智的..。将脚本集中在单个Jenkins DSL代码库中创建Jenkins作业并不是一个坏主意。
https://stackoverflow.com/questions/43999508
复制相似问题