Browse Source

Copy pipeline Jenkinsfile

1031
Kevin Mok 2 weeks ago
parent
commit
3a1f3b9fe4
Signed by: Kevin Mok <kmok@redhat.com> GPG Key ID: 10B001347552F396
1 changed files with 260 additions and 0 deletions
  1. 260
    0
      full/Jenkinsfile.pr-bdd-tests

+ 260
- 0
full/Jenkinsfile.pr-bdd-tests View File

@@ -0,0 +1,260 @@
import org.jenkinsci.plugins.workflow.libs.Library
@Library('jenkins-pipeline-shared-libraries')_

changeAuthor = env.ghprbPullAuthorLogin ?: CHANGE_AUTHOR
changeBranch = env.ghprbSourceBranch ?: BRANCH_NAME
changeTarget = env.ghprbTargetBranch ?: CHANGE_TARGET
changeId = env.ghprbPullId ?: CHANGE_ID

RUNTIMES_DEPLOY = 'kogito-runtimes-deploy'
EXAMPLES_DEPLOY = 'kogito-examples-deploy'
IMAGES_DEPLOY = 'kogito-images-deploy'
OPERATOR_DEPLOY = 'kogito-operator-deploy'
OPTAPLANNER_DEPLOY = 'optaplanner-deploy'

// Map of executed jobs
// See https://javadoc.jenkins.io/plugin/workflow-support/org/jenkinsci/plugins/workflow/support/steps/build/RunWrapper.html
// for more options on built job entity
JOBS = [:]

FAILED_STAGES=[]
UNSTABLE_STAGES=[]

// Should be multibranch pipeline
pipeline {
agent {
label 'kie-rhel7-priority && !master'
}

triggers {
cron ('H 0 * * *')
}

environment {
KOGITO_CI_EMAIL_TO = credentials('KOGITO_CI_EMAIL_TO')

// We use quay as temporary registry for testing between the jobs instead of Openshift, due to https://issues.redhat.com/browse/KOGITO-2219
IMAGE_REGISTRY_CREDENTIALS = 'nightly_kogito'
IMAGE_REGISTRY = 'quay.io'
IMAGE_NAMESPACE = 'kiegroup'
IMAGE_NAME_SUFFIX = 'nightly'
BUILD_NAME = "${getPRRepoName()}-pr-${changeId}-tests"
TEMP_TAG = "temp-${env.BUILD_NAME}"
BRANCH_FOR_LATEST='master'
}

stages {
stage('Initialize') {
steps {
script {
echo "temporary tag is ${env.TEMP_TAG}"
echo "build name is ${env.BUILD_NAME}"

currentBuild.displayName = env.BUILD_NAME
}
}
}

stage('Build & Deploy Kogito Runtimes') {
steps {
script {
echo "Call ${RUNTIMES_DEPLOY} job"
def buildParams = getDefaultBuildParams()
addAuthorBranchParamsIfExist(buildParams, getPRRepoName())
addStringParam(buildParams, 'MAVEN_DEPLOY_REPOSITORY', getArtifactsRepositoryParam())
// images and operator deploy testing will use older working artifacts if that one fails
buildJob(RUNTIMES_DEPLOY, buildParams, false)
}
}
post {
failure {
addFailedStage()
}
}
}

stage('Build & Deploy OptaPlanner') {
steps {
script {
echo "Call ${OPTAPLANNER_DEPLOY} job"
def buildParams = getDefaultBuildParams()
addStringParam(buildParams, 'MAVEN_DEPENDENCIES_REPOSITORY', getArtifactsRepositoryParam())
addStringParam(buildParams, 'MAVEN_DEPLOY_REPOSITORY', getArtifactsRepositoryParam())

buildJob(OPTAPLANNER_DEPLOY, buildParams, false)
}
}
post {
failure {
addFailedStage()
}
}
}

stage('Build & Deploy Kogito Examples') {
steps {
script {
echo "Call ${EXAMPLES_DEPLOY} job"
def buildParams = getDefaultBuildParams()
addStringParam(buildParams, 'MAVEN_DEPENDENCIES_REPOSITORY', getArtifactsRepositoryParam())
addStringParam(buildParams, 'MAVEN_DEPLOY_REPOSITORY', getArtifactsRepositoryParam())
// images and operator deploy testing will use older working artifacts if that one fails
buildJob(EXAMPLES_DEPLOY, buildParams, false)
}
}
post {
failure {
addFailedStage()
}
}
}

stage('Build & Deploy Images') {
steps {
script {
echo "Call ${IMAGES_DEPLOY} job"

def buildParams = getDefaultBuildParams()
addImageBuildParams(buildParams, '', env.TEMP_TAG, true, false)
addExamplesParams(buildParams)
addStringParam(buildParams, 'MAVEN_ARTIFACT_REPOSITORY', getArtifactsRepositoryParam()) // Get artifacts from specific repository if not empty

buildJob(IMAGES_DEPLOY, buildParams, false)
}
}
post {
failure {
addFailedStage()
}
}
}

stage('Build & Deploy Operator') {
when {
expression { return isOperatorDeploy() }
}
steps {
script {
echo "Call ${OPERATOR_DEPLOY} job"
def buildParams = getDefaultBuildParams()
addImageBuildParams(buildParams, '', env.TEMP_TAG, true, false)

// For BDD tests
addBooleanParam(buildParams, 'KOGITO_IMAGES_IN_OPENSHIFT_REGISTRY', false)
addStringParam(buildParams, 'KOGITO_IMAGES_REGISTRY', env.IMAGE_REGISTRY)
addStringParam(buildParams, 'KOGITO_IMAGES_NAMESPACE', env.IMAGE_NAMESPACE)
addStringParam(buildParams, 'KOGITO_IMAGES_NAME_SUFFIX', env.IMAGE_NAME_SUFFIX)
addStringParam(buildParams, 'KOGITO_IMAGES_TAG', env.TEMP_TAG)
addExamplesParams(buildParams)
addStringParam(buildParams, 'MAVEN_ARTIFACT_REPOSITORY', getArtifactsRepositoryParam()) // Get artifacts from specific repository if not empty

buildJob(OPERATOR_DEPLOY, buildParams, false)
}
}
post {
failure {
addFailedStage()
}
}
}

}
}

def buildJob(String jobName, List buildParams, boolean propagate=true){
echo "Build ${jobName} with params ${buildParams} and propagate = ${propagate}"

def job = build(job: "../${jobName}", wait: true, parameters: buildParams, propagate: propagate)
JOBS[jobName] = job

// Set Unstable if we don't propagate and job failed
if(!propagate && !isJobSucceeded(jobName)){
addUnstableStage()
unstable("Job ${jobName} finished with result ${job.getResult()}")
}
return job
}

def getJob(String jobName){
return JOBS[jobName]
}

boolean isJobSucceeded(String jobName){
def job = getJob(jobName)
return job ? job.getResult() == 'SUCCESS' : false
}

void addFailedStage(){
FAILED_STAGES.add("${STAGE_NAME}")
}
void addUnstableStage(){
UNSTABLE_STAGES.add("${STAGE_NAME}")
}

List getDefaultBuildParams(){
List params = []
addStringParam(params, 'DISPLAY_NAME', env.BUILD_NAME)
return params
}

boolean doesBranchExist(String repo, String author, String branch) {
return githubscm.getRepositoryScm(repo, author, branch) != null
}

void addAuthorBranchParamsIfExist(List params, String repo) {
if (doesBranchExist(repo, changeAuthor, changeBranch))
addStringParam(params, 'GIT_AUTHOR', changeAuthor)
addStringParam(params, 'BUILD_BRANCH_NAME', changeBranch)
}
}

void addExamplesParams(List buildParams){
def author = ''
def branch = ''
if (doesBranchExist('kogito-examples', changeAuthor, changeBranch)) {
author = changeAuthor
branch = changeBranch
} else if (doesBranchExist('kogito-examples', 'kiegroup', changeTarget)) {
author = 'kiegroup'
branch = changeTarget
} else {
author = 'kiegroup'
branch = 'master'
}
addStringParam(buildParams, 'EXAMPLES_URI', "https://github.com/${author}/kogito-examples")
addStringParam(buildParams, 'EXAMPLES_REF', branch)
}

void addImageBuildParams(List buildParams = [], String paramsPrefix = '', String tag, boolean isRegistryIncluded = false, boolean isFinalImage = false){
if(isRegistryIncluded) {
addStringParam(buildParams, constructKey(paramsPrefix, 'IMAGE_REGISTRY_CREDENTIALS'), env.IMAGE_REGISTRY_CREDENTIALS)
addStringParam(buildParams, constructKey(paramsPrefix, 'IMAGE_REGISTRY'), env.IMAGE_REGISTRY)
addStringParam(buildParams, constructKey(paramsPrefix, 'IMAGE_NAMESPACE'), env.IMAGE_NAMESPACE)
}
addStringParam(buildParams, constructKey(paramsPrefix, 'IMAGE_NAME_SUFFIX'), env.IMAGE_NAME_SUFFIX)
addStringParam(buildParams, constructKey(paramsPrefix, 'IMAGE_TAG'), tag)
}

void addStringParam(List params, String key, String value){
params.add(string(name: key, value: value))
}

void addBooleanParam(List params, String key, boolean value){
params.add(booleanParam(name: key, value: value))
}

String constructKey(String prefix, String paramId){
return prefix == null || prefix == '' ? paramId : "${prefix}_${paramId}"
}

String getArtifactsRepositoryParam(){
return credentials('PR_CHECK_MAVEN_REPOSITORY')
}

String getPRRepoName() {
return env.ghprbGhRepository.split('/')[1]
}


Loading…
Cancel
Save