Считать параметр и значение задания из URL задания - PullRequest
0 голосов
/ 08 октября 2019

Я создал два конвейерных задания jobCreatorGitHub и jobCreatorGitHubCustomizedBuild с использованием механизма DSL задания.

Каждое задание имеет гиперссылку на другое задание (т. Е. Из 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()
"""
        )
     }
  }
}
...