我有两个詹金斯工作,分别是Job1和Job2。 Job1使用Jenkinsfile执行,而Job2使用Groovy脚本执行。
使用的参数是键值对类型,这些参数将从Jenkinsfile传递到Groovy Script,以便与Job1并行运行Job2。
请提出一种解决上述情况的方法。
下面是我的代码:
Job1中使用的詹金斯(呼叫者)文件:
#!groovy
library <internal library I am using>
pipeline {
agent any
stages {
stage ('callParallelJob') {
steps {
script {
------- Some code------
def gitCommitterEmail = sh (
script: 'git --no-pager show -s --format=\'%ae\'',
returnStdout: true
).trim()
echo "git committer: ${gitCommitterEmail}"
appConfig.gitCommitterEmail = gitCommitterEmail
def gitBranch = "${env.GIT_BRANCH}".trim()
appConfig.gitBranch = gitBranch
def jenkinsBuildUrl = "${env.BUILD_URL}".trim()
appConfig.jenkinsBuildUrl = jenkinsBuildUrl
def ciData = [
'git': [
'git_repo': "${git_repo}",
'git_branch': "${env.BRANCH_NAME}",
'git_committer': "${gitCommitterEmail}",
'git_commit': "${GIT_COMMIT}"
],
'jenkins': [
'build_url': "${env.BUILD_URL}",
'job_name': "${JOB_NAME}",
'timestamp': "${BUILD_TIMESTAMP}"
]
]
writeYaml file: 'ci.yml', data: ciData
echo 'calling another job'
build job: '<job2Namehere>, parameters: [
string(name: 'Testparam', value: "123"),
], propagate: true, wait: false
echo 'called another job'
}
}
}
我想将appConfig和ci.yml数据传递到以下groovy脚本
Job2中使用的Groovy文件:
pipeline {
agent any
stages {
stage('Experiment'){
steps{
script{
sh 'echo ${Testparam}'
-------Some code here-------
}}}}}