Hopefully fixed pipeline.

This commit is contained in:
Andrew Pitt 2020-01-06 14:05:28 -05:00
parent 84b09177f5
commit 2eeed5fbd4

89
Jenkinsfile vendored
View file

@ -1,8 +1,8 @@
def appName=env.APP_NAME def appName=env.APP_NAME
def gitSourceUrl=env.GIT_SOURCE_URL def gitSourceUrl=env.GIT_SOURCE_URL
def gitSourceRef=env.GIT_SOURCE_REF def gitSourceRef=env.GIT_SOURCE_REF
def project="" def project=env.PROJECT_NAME
def projectVersion="" def projectVersion=""
pipeline { pipeline {
agent { agent {
@ -10,67 +10,78 @@ pipeline {
} }
stages { stages {
stage("Initialize") { stage('Initialize') {
project = env.PROJECT_NAME steps {
echo "appName: ${appName}" echo "appName: ${appName}"
echo "gitSourceUrl: ${gitSourceUrl}" echo "gitSourceUrl: ${gitSourceUrl}"
echo "gitSourceRef: ${gitSourceRef}" echo "gitSourceRef: ${gitSourceRef}"
}
} }
stage("Checkout") { stage('Checkout') {
steps {
echo "Checkout source." echo "Checkout source."
git url: "${gitSourceUrl}", branch: "${gitSourceRef}" git url: "${gitSourceUrl}", branch: "${gitSourceRef}"
echo "Read POM info." echo "Read POM info."
pom = readMavenPom file: 'pom.xml' pom = readMavenPom file: 'pom.xml'
projectVersion = pom.version projectVersion = pom.version
}
} }
stage("Build JAR") { stage('Build JAR') {
steps {
echo "Build the app." echo "Build the app."
sh "mvn clean package" sh "mvn clean package"
}
} }
stage("Quality Check") { stage('Quality Check') {
steps {
sh "mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install -Dmaven.test.failure.ignore=false" sh "mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install -Dmaven.test.failure.ignore=false"
sh "mvn sonar:sonar -Dsonar.jacoco.reportPaths=target/coverage-reports/jacoco-unit.exec -Dsonar.host.url=http://sonarqube.cicd.svc:9000" sh "mvn sonar:sonar -Dsonar.jacoco.reportPaths=target/coverage-reports/jacoco-unit.exec -Dsonar.host.url=http://sonarqube.cicd.svc:9000"
// sh "mvn org.cyclonedx:cyclonedx-maven-plugin:makeBom" // sh "mvn org.cyclonedx:cyclonedx-maven-plugin:makeBom"
//dependencyTrackPublisher(artifact: 'target/bom.xml', artifactType: 'bom', projectName: "${appName}", projectVersion: "${projectVersion}", synchronous: false) //dependencyTrackPublisher(artifact: 'target/bom.xml', artifactType: 'bom', projectName: "${appName}", projectVersion: "${projectVersion}", synchronous: false)
}
} }
stage("Build Image") { stage('Build Image') {
steps {
echo "Build container image." echo "Build container image."
// unstash name:"jar"
openshift.withCluster() { openshift.withCluster() {
openshift.withProject('cicd') { openshift.withProject('cicd') {
sh "oc start-build ${appName}-s2i-build --from-file=target/app.jar -n cicd --follow" sh "oc start-build ${appName}-s2i-build --from-file=target/app.jar -n cicd --follow"
} }
} }
}
} }
stage("Tag DEV") { stage('Tag DEV') {
agent { agent {
label 'jenkins-slave-skopeo' label 'jenkins-slave-skopeo'
} }
steps {
script { script {
openshift.withCluster() { openshift.withCluster() {
withCredentials([usernamePassword(credentialsId: "${openshift.project()}-quay-creds-secret", usernameVariable: "QUAY_USERNAME", passwordVariable: "QUAY_PASSWORD")]) { withCredentials([usernamePassword(credentialsId: "${openshift.project()}-quay-creds-secret", usernameVariable: "QUAY_USERNAME", passwordVariable: "QUAY_PASSWORD")]) {
sh "skopeo copy docker://quay.io/${QUAY_USERNAME}/${QUAY_REPOSITORY}:latest docker://quay.io/${QUAY_USERNAME}/${QUAY_REPOSITORY}:dev --src-creds \"$QUAY_USERNAME:$QUAY_PASSWORD\" --dest-creds \"$QUAY_USERNAME:$QUAY_PASSWORD\" --src-tls-verify=false --dest-tls-verify=false" sh "skopeo copy docker://quay.io/${QUAY_USERNAME}/${QUAY_REPOSITORY}:latest docker://quay.io/${QUAY_USERNAME}/${QUAY_REPOSITORY}:dev --src-creds \"$QUAY_USERNAME:$QUAY_PASSWORD\" --dest-creds \"$QUAY_USERNAME:$QUAY_PASSWORD\" --src-tls-verify=false --dest-tls-verify=false"
} }
} }
} }
}
} }
stage("Deploy DEV") { stage('Deploy DEV') {
steps {
echo "Deploy to DEV." echo "Deploy to DEV."
openshift.withCluster() { openshift.withCluster() {
openshift.withProject("${appName}-dev") { openshift.withProject("${appName}-dev") {
echo "Rolling out to DEV." echo "Rolling out to DEV."
def dc = openshift.selector('dc', "${appName}") def dc = openshift.selector('dc', "${appName}")
dc.rollout().latest() dc.rollout().latest()
dc.rollout().status() dc.rollout().status()
} }
} }
}
} }
stage("Integration Tests") { stage('Integration Tests') {
echo "Running Integration tests..." echo "Running Integration tests..."
sh "mvn verify -Pfailsafe" sh "mvn verify -Pfailsafe"
} }
stage("Tag UAT") { stage('Tag UAT') {
agent { agent {
label 'jenkins-slave-skopeo' label 'jenkins-slave-skopeo'
} }
@ -82,16 +93,16 @@ pipeline {
} }
} }
} }
stage("Deploy UAT") { stage('Deploy UAT') {
echo "Deploy to UAT." echo "Deploy to UAT."
openshift.withCluster() { openshift.withCluster() {
openshift.withProject("${appName}-uat") { openshift.withProject("${appName}-uat") {
echo "Rolling out to UAT." echo "Rolling out to UAT."
def dc = openshift.selector('dc', "${appName}") def dc = openshift.selector('dc', "${appName}")
dc.rollout().latest() dc.rollout().latest()
dc.rollout().status() dc.rollout().status()
} }
} }
} }
} }
} }