我已经使用作业DSL机制创建了两个管道作业jobCreatorGitHub和jobCreatorGitHubCustomizedBuild。
每个作业都有指向另一个作业的超链接。(例如,从jobCreatorGitHub可以导航到jobCreatorGitHubCustomizedBuild等)
我要实现的是,当任何作业已加载参数值,并且如果他们想从那里导航到另一个作业时,我想将这些参数和值带到另一个作业,以便预先加载值。
即我的代码中使用的genParamUrlString应该包含参数名称和值。如何阅读。
//First pipeline job
pipelineJob("${CVRootFolder}/jobCreatorGitHub") {
description("Createa git job")
concurrentBuild(false)
authenticationToken('abc')
configure {
it / 'properties' / 'org.jenkinsci.plugins.workflow.job.properties.BuildDiscarderProperty' {
strategy(class: 'hudson.tasks.LogRotator') {
'daysToKeep'(daysToKeepBuilds)
'numToKeep'('-1')
'artifactDaysToKeep'(daysToKeepBuilds)
'artifactNumToKeep'('-1')
}
}
}
// Using environment variables is a workaround to avoid script approval for every single job :(
environmentVariables(
globalEnv
)
parameters {
validatingStringParameterDefinition {
name 'GitHubURL'
regex urlRegex
defaultValue 'git@github.com:MY_COMPANY/MyProject.git'
failedValidationMessage """Your URL is incorrect. It must start with 'git@github.com'."""
description '<p>Supported projects: Flavored'
}
validatingStringParameterDefinition {
name 'branch'
regex branchRegex
defaultValue 'master'
failedValidationMessage ''
description ''
}
validatingStringParameterDefinition {
name 'flavor'
regex flavorRegex
defaultValue ''
failedValidationMessage 'Flavor is always <customer-id>/<project-id>, the project id must have 3 characters.'
description '<p>Examples:</p>\n' +
'<ul>\n' +
'<li>TEST/AB1</li>\n' +
'<li>TEST2/XY</li>\n' +
'<li>PROD/FG4</li>\n' +
'</ul>\n'
}
choiceParam('mode', ['CreateNew', 'DisableExisting'], '')
//Hyper link to jobCreatorGitHubCustomizedBuildis created here when calling getParameterDescForSelectionTypes method.
choiceParam('selection', selectionTypeFromGlobalConfig, getParameterDescForSelectionTypes(origPropsGlobal, selectionTypeFromGlobalConfig, CVRootFolderJobPath, genParamUrlString).replace('jobCreatorNameToBeReplaced', 'jobCreatorGitHubCustomizedBuild'))
booleanParam('runFullBuilds', true, 'Enable Full builds for this job')
}
definition {
cps {
script(
"""
$libraryLoader
jobCreatorGitHub()
"""
)
}
}
}
// 2nd pipeline job
pipelineJob("${CVRootFolder}/jobCreatorGitHubCustomizedBuild") {
description("Creates a CV Customized job")
concurrentBuild(false)
authenticationToken('abc')
configure {
it / 'properties' / 'org.jenkinsci.plugins.workflow.job.properties.BuildDiscarderProperty' {
strategy(class: 'hudson.tasks.LogRotator') {
'daysToKeep'(daysToKeepBuilds)
'numToKeep'('-1')
'artifactDaysToKeep'(daysToKeepBuilds)
'artifactNumToKeep'('-1')
}
}
}
// Using environment variables is a workaround to avoid script approval for every single job :(
environmentVariables(
globalEnv
)
parameters {
validatingStringParameterDefinition {
name 'GitHubURL'
regex urlRegex
defaultValue 'git@github.com:MY_COMPANY/MyProject.git'
failedValidationMessage """Your URL is incorrect. It must start with 'git@github.com'."""
description '<p>Supported projects: Flavored'
}
validatingStringParameterDefinition {
name 'branch'
regex branchRegex
defaultValue 'master'
failedValidationMessage ''
description ''
}
validatingStringParameterDefinition {
name 'flavor'
regex flavorRegex
defaultValue ''
failedValidationMessage 'Flavor is always <customer-id>/<project-id>, the project id must have 3 characters.'
description '<p>Examples:</p>\n' +
'<ul>\n' +
'<li>TEST/AB1</li>\n' +
'<li>TEST2/XY</li>\n' +
'<li>PROD/FG4</li>\n' +
'</ul>\n'
}
choiceParam('mode', ['CreateNew', 'DisableExisting'], '')
booleanParam('buildSWXY', true, 'Execute software tests.')
booleanParam('buildMY', true, 'Execute MY link.')
booleanParam('buildVER', false, """Create a new version.
<p>want to schedule build based on selection type(${selectionTypeFromGlobalConfig.join('/')}) ? <a href="${JENKINS_URL}/job/${CVRootFolderJobPath}/job/jobCreatorGitHub/${genParamUrlString == '' ? "parambuild/?${genParamUrlString}" : 'build?delay=0sec'}" target="_blank">schedule build</a></p>
""")
booleanParam('runFullBuilds', true, 'Enable Full builds for this job')
booleanParam('highPrio', false, 'Enable high priority flag for this job')
textParam('commitComment', '')
}
definition {
cps {
script(
"""
$libraryLoader
jobCreatorGitHub()
"""
)
}
}
}