Skip to content

Commit

Permalink
Move jjb job to shared library
Browse files Browse the repository at this point in the history
  • Loading branch information
Itxaka committed Nov 17, 2020
1 parent 223d7ae commit a959658
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 124 deletions.
90 changes: 3 additions & 87 deletions ci/jenkins/pipelines/prs/skuba-jjb-validation.Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,90 +1,6 @@
// this pipeline update all jenkins pipelines via jenkins job builder plugin
// this pipeline is only used by the PRs under the name jjb-validation

pipeline {
agent { node { label 'caasp-team-private-integration' } }
environment {
GITHUB_TOKEN = credentials('github-token')
JENKINS_JOB_CONFIG = credentials('jenkins-job-config')
REQUESTS_CA_BUNDLE = "/var/lib/ca-certificates/ca-bundle.pem"
PR_CONTEXT = 'jenkins/skuba-jjb-validation'
PR_MANAGER = 'ci/jenkins/pipelines/prs/helpers/pr-manager'
TERRAFORM_STACK_NAME = "${BUILD_NUMBER}-${JOB_NAME.replaceAll("/","-")}".take(70)
}
stages {
stage('Collaborator Check') { steps { script {
if (env.BRANCH_NAME.startsWith('PR')) {
def membersResponse = httpRequest(
url: "https://api.github.com/repos/SUSE/skuba/collaborators/${CHANGE_AUTHOR}",
authentication: 'github-token',
validResponseCodes: "204:404")
@Library('caasp-jenkins-lib@master') _

if (membersResponse.status == 204) {
echo "Test execution for collaborator ${CHANGE_AUTHOR} allowed"

} else {
def allowExecution = false

try {
timeout(time: 5, unit: 'MINUTES') {
allowExecution = input(id: 'userInput', message: "Change author is not a SUSE member: ${CHANGE_AUTHOR}", parameters: [
booleanParam(name: 'allowExecution', defaultValue: false, description: 'Run tests anyway?')
])
}
} catch(err) {
def user = err.getCauses()[0].getUser()
if('SYSTEM' == user.toString()) {
echo "Timeout while waiting for input"
} else {
allowExecution = false
echo "Unhandled error:\n${err}"
}
}


if (!allowExecution) {
echo "Test execution for unknown user (${CHANGE_AUTHOR}) disallowed"
error(message: "Test execution for unknown user (${CHANGE_AUTHOR}) disallowed")
return;
}
}
}
} } }

stage('Setting GitHub in-progress status') { steps {
sh(script: "${PR_MANAGER} update-pr-status ${PR_CONTEXT} 'pending'", label: "Sending pending status")
} }

stage('Info') { steps {
sh(script: "make -f ci/Makefile info", label: 'Info')
} }

stage('Setup Environment') { steps {
sh(script: 'python3 -m venv venv', label: 'Setup Python Virtualenv')
sh(script: 'venv/bin/pip install jenkins-job-builder==2.10.0', label: 'Install Dependencies')
} }

stage('Test Jobs') { steps {
sh(script: """
source ${WORKSPACE}/venv/bin/activate
make -f ci/Makefile test_jenkins_jobs
""", label: 'Test Jenkins Jobs')
zip archive: true, dir: 'ci/jenkins/jobs', zipFile: 'jenkins_jobs.zip'
} }
}
post {
cleanup {
dir("${WORKSPACE}") {
deleteDir()
}
}
unstable {
sh(script: "${PR_MANAGER} update-pr-status ${PR_CONTEXT} 'failure'", label: "Sending failure status")
}
failure {
sh(script: "{PR_MANAGER} update-pr-status ${PR_CONTEXT} 'failure'", label: "Sending failure status")
}
success {
sh(script: "${PR_MANAGER} update-pr-status ${PR_CONTEXT} 'success'", label: "Sending success status")
}
}
}
jjbValidation()
42 changes: 5 additions & 37 deletions ci/jenkins/pipelines/skuba-jjb.Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,38 +1,6 @@
// this pipeline update all jenkins pipelines via jenkins job builder plugin
pipeline {
agent { node { label 'caasp-team-private-integration' } }
environment {
JENKINS_JOB_CONFIG = credentials('jenkins-job-config')
REQUESTS_CA_BUNDLE = "/var/lib/ca-certificates/ca-bundle.pem"
TERRAFORM_STACK_NAME = "${BUILD_NUMBER}-${JOB_NAME.replaceAll("/","-")}".take(70)
}
stages {
stage('Info') { steps {
sh(script: "make -f ci/Makefile info", label: 'Info')
} }
stage('Setup Environment') { steps {
sh(script: 'python3 -m venv venv', label: 'Setup Python Virtualenv')
sh(script: 'venv/bin/pip install jenkins-job-builder==2.10.0', label: 'Install Dependencies')
} }
stage('Test Jobs') { steps {
sh(script: """
source ${WORKSPACE}/venv/bin/activate
make -f ci/Makefile test_jenkins_jobs
""", label: 'Test Jenkins Jobs')
zip archive: true, dir: 'ci/jenkins/jobs', zipFile: 'jenkins_jobs.zip'
} }
stage('Update Jobs') { steps {
sh(script: """
source ${WORKSPACE}/venv/bin/activate
make -f ci/Makefile update_jenkins_jobs
""", label: 'Update Jenkins Jobs')
} }
}
post {
cleanup {
dir("${WORKSPACE}") {
deleteDir()
}
}
}
}
// this pipeline runs for master every hour under the name caasp-jjb-skuba

@Library('caasp-jenkins-lib@master') _

caaspjjbskuba()

0 comments on commit a959658

Please sign in to comment.