I have two Jenkins job say Job1 and Job2. Job1 uses Jenkinsfile to execute and Job2 uses Groovy script to execute.
Parameters being used are of type key-value pair, and these parameters will be passed from Jenkinsfile to Groovy Script so as to run Job2 parallel to Job1.
Please suggest a way to do the above scenario.
Below is my code:
Jenkins(caller)file used in 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'
}
}
}
I want to pass appConfig and ci.yml data to below groovy script
Groovy file used in Job2 :
pipeline {
agent any
stages {
stage('Experiment'){
steps{
script{
sh 'echo ${Testparam}'
-------Some code here-------
}}}}}