无法通过 Jenkins 中的 DSL 脚本 find/locate 生成作业
Unable to find/locate generated job by DSL script in Jenkins
我是运行 Jenkins dsl 脚本来生成新的作业。
在日志文件中,一切正常,作业已创建。
Created_xdbd6ajc2_le5_SEED_JOB_UNIX_xdbd6ajc2_le5
Existing items:
GeneratedJob{name='Created_xdbd6ajc2_le5_SEED_JOB_UNIX_xdbd6ajc2_le5'}
Added views:
GeneratedView{name='TEMPLATE_BD6'}
Started calculate disk usage of build
Finished Calculation of disk usage of build in 0 seconds
Started calculate disk usage of workspace
Finished Calculation of disk usage of workspace in 0 seconds
Finished: SUCCESS
问题是我找不到Created_xdbd6ajc2_le5_SEED_JOB_UNIX_xdbd6ajc2_le5工作!!
我在TEMPLATE_BD6里看了看,什么都没有。
另外,我搜索了所有jenkins文件夹,但没有办法!
看看我的 DSL 脚本的结构:
def jobParams= [
'gitUrl': "${GIT_SSH_URL}",
'projectName': "${PROJECT}",
'composantType': "${COMPOSANT_TYPE}",
'elements': "${ELEMENTS}"
]
def repoGitName = (jobParams.gitUrl =~ "(.*)/(.*)/(.*).git")[0][3]
def repoShortName = repoGitName
//def composantPath = "${jobParams.projectName}/${jobParams.composantType}/${repoShortName}"
def composantPath = "${repoShortName}"
def gitConfig = ['gitUrl': jobParams.gitUrl]
def Created_Job_name = "Created_${composantPath}_SEED_JOB_${jobParams.composantType}_${repoShortName}"
listView('TEMPLATE_BD6') {
job(Created_Job_name) {
logRotator {
daysToKeep(30)
}
scm {
git {
remote {
url(gitConfig.gitUrl)
}
extensions {
pruneBranches()
}
}
}
triggers{ scm('') }
steps {
dsl{
text(readFileFromWorkspace("src/groovy/CPF_${jobParams.composantType}_JOBDSL.groovy"))
ignoreExisting()
removeAction('DISABLE')
removeViewAction('IGNORE')
}
}
}
}
编辑
我尝试了@agabrys 提出的解决方案,但 Jenkins 仪表板中没有显示生成的项目,甚至控制台也确认了这些项目的生成!
看图和结果控制台:
图片
控制台
Existing items:
GeneratedJob{name='Created_xdbd6ajc2_le5_SEED_JOB_UNIX_xdbd6ajc2_le5'}
Added views:
GeneratedView{name='TEMPLATE_BD6'}
Started calculate disk usage of build
Finished Calculation of disk usage of build in 0 seconds
Started calculate disk usage of workspace
Finished Calculation of disk usage of workspace in 0 seconds
Finished: SUCCESS
Jenkins 中是否有我遗漏的任何配置?
好吧,我终于找到了解决问题的方法。我错过了两个步骤:
首先,我应该指定创建的作业类型为freestyle object !!
换句话说,而不是:
job(Created_Job_name) {
logRotator {
daysToKeep(30)
}
我应该写:
freeStyleJob(Created_Job_name) {
logRotator {
daysToKeep(30)
}
第二件事,,新作业的名称应该包含根路径:
换句话说,如果在文件夹“bd6”中的“template_bd6”中创建名为“test”的新作业作为示例。然后,新工作的名称应该是:
Created_Job_name = "bd6/template_bd6/test"
我是运行 Jenkins dsl 脚本来生成新的作业。 在日志文件中,一切正常,作业已创建。
Created_xdbd6ajc2_le5_SEED_JOB_UNIX_xdbd6ajc2_le5
Existing items:
GeneratedJob{name='Created_xdbd6ajc2_le5_SEED_JOB_UNIX_xdbd6ajc2_le5'}
Added views:
GeneratedView{name='TEMPLATE_BD6'}
Started calculate disk usage of build
Finished Calculation of disk usage of build in 0 seconds
Started calculate disk usage of workspace
Finished Calculation of disk usage of workspace in 0 seconds
Finished: SUCCESS
问题是我找不到Created_xdbd6ajc2_le5_SEED_JOB_UNIX_xdbd6ajc2_le5工作!! 我在TEMPLATE_BD6里看了看,什么都没有。
另外,我搜索了所有jenkins文件夹,但没有办法! 看看我的 DSL 脚本的结构:
def jobParams= [
'gitUrl': "${GIT_SSH_URL}",
'projectName': "${PROJECT}",
'composantType': "${COMPOSANT_TYPE}",
'elements': "${ELEMENTS}"
]
def repoGitName = (jobParams.gitUrl =~ "(.*)/(.*)/(.*).git")[0][3]
def repoShortName = repoGitName
//def composantPath = "${jobParams.projectName}/${jobParams.composantType}/${repoShortName}"
def composantPath = "${repoShortName}"
def gitConfig = ['gitUrl': jobParams.gitUrl]
def Created_Job_name = "Created_${composantPath}_SEED_JOB_${jobParams.composantType}_${repoShortName}"
listView('TEMPLATE_BD6') {
job(Created_Job_name) {
logRotator {
daysToKeep(30)
}
scm {
git {
remote {
url(gitConfig.gitUrl)
}
extensions {
pruneBranches()
}
}
}
triggers{ scm('') }
steps {
dsl{
text(readFileFromWorkspace("src/groovy/CPF_${jobParams.composantType}_JOBDSL.groovy"))
ignoreExisting()
removeAction('DISABLE')
removeViewAction('IGNORE')
}
}
}
}
编辑 我尝试了@agabrys 提出的解决方案,但 Jenkins 仪表板中没有显示生成的项目,甚至控制台也确认了这些项目的生成!
看图和结果控制台:
图片
控制台
Existing items:
GeneratedJob{name='Created_xdbd6ajc2_le5_SEED_JOB_UNIX_xdbd6ajc2_le5'}
Added views:
GeneratedView{name='TEMPLATE_BD6'}
Started calculate disk usage of build
Finished Calculation of disk usage of build in 0 seconds
Started calculate disk usage of workspace
Finished Calculation of disk usage of workspace in 0 seconds
Finished: SUCCESS
Jenkins 中是否有我遗漏的任何配置?
好吧,我终于找到了解决问题的方法。我错过了两个步骤:
首先,我应该指定创建的作业类型为freestyle object !!
换句话说,而不是:
job(Created_Job_name) {
logRotator {
daysToKeep(30)
}
我应该写:
freeStyleJob(Created_Job_name) {
logRotator {
daysToKeep(30)
}
第二件事,,新作业的名称应该包含根路径: 换句话说,如果在文件夹“bd6”中的“template_bd6”中创建名为“test”的新作业作为示例。然后,新工作的名称应该是:
Created_Job_name = "bd6/template_bd6/test"