57 lines
1.4 KiB
Groovy
57 lines
1.4 KiB
Groovy
pipeline {
|
|
agent { label 'jjb' }
|
|
options {
|
|
timestamps()
|
|
ansiColor('xterm')
|
|
}
|
|
stages {
|
|
stage('Prepare Metadata') {
|
|
steps {
|
|
script {
|
|
wrap([$class: 'BuildUser']) {
|
|
env.RUN_TRIGGER_USER = env.BUILD_USER_ID ?: env.BUILD_USER ?: 'system'
|
|
env.RUN_TRIGGER_NAME = env.BUILD_USER ?: env.BUILD_USER_ID ?: 'system'
|
|
}
|
|
currentBuild.displayName = "#${env.BUILD_NUMBER} jjb"
|
|
currentBuild.description = "by=${env.RUN_TRIGGER_NAME}; jjbPath=${params.JJB_PATH}"
|
|
}
|
|
}
|
|
}
|
|
stage('Validate Input') {
|
|
steps {
|
|
sh '''
|
|
set -eux
|
|
test -d "${JJB_PATH}"
|
|
test -f "${JJB_PATH}/global.yaml"
|
|
'''
|
|
}
|
|
}
|
|
stage('Deploy Jobs') {
|
|
steps {
|
|
withCredentials([usernamePassword(
|
|
credentialsId: 'jenkins-admin-userpass',
|
|
usernameVariable: 'J_USER',
|
|
passwordVariable: 'J_PASS'
|
|
)]) {
|
|
sh '''
|
|
set -eux
|
|
cat > /tmp/jenkins-job-builder.ini <<EOF
|
|
[job_builder]
|
|
ignore_cache=True
|
|
keep_descriptions=True
|
|
recursive=True
|
|
|
|
[jenkins]
|
|
url=${JENKINS_URL_INTERNAL}
|
|
user=${J_USER}
|
|
password=${J_PASS}
|
|
EOF
|
|
jenkins-jobs --conf /tmp/jenkins-job-builder.ini --flush-cache update "${JJB_PATH}"
|
|
rm -f /tmp/jenkins-job-builder.ini
|
|
'''
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|