-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding a hygieia-enabled jenkinsfile * Fixing artifact name
- Loading branch information
Showing
1 changed file
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
library identifier: "pipeline-library@master", | ||
retriever: modernSCM( | ||
[ | ||
$class: "GitSCMSource", | ||
remote: "https://github.com/redhat-cop/pipeline-library.git" | ||
] | ||
) | ||
|
||
openshift.withCluster() { | ||
env.NAMESPACE = openshift.project() | ||
env.POM_FILE = env.BUILD_CONTEXT_DIR ? "${env.BUILD_CONTEXT_DIR}/pom.xml" : "pom.xml" | ||
env.APP_NAME = "${JOB_NAME}".replaceAll(/-build.*/, '') | ||
echo "Starting Pipeline for ${APP_NAME}..." | ||
env.BUILD = "${env.NAMESPACE}" | ||
env.DEV = "${APP_NAME}-dev" | ||
env.STAGE = "${APP_NAME}-stage" | ||
env.PROD = "${APP_NAME}-prod" | ||
} | ||
|
||
pipeline { | ||
// Use Jenkins Maven slave | ||
// Jenkins will dynamically provision this as OpenShift Pod | ||
// All the stages and steps of this Pipeline will be executed on this Pod | ||
// After Pipeline completes the Pod is killed so every run will have clean | ||
// workspace | ||
agent { | ||
label 'maven' | ||
} | ||
|
||
// Pipeline Stages start here | ||
// Requeres at least one stage | ||
stages { | ||
|
||
// Checkout source code | ||
// This is required as Pipeline code is originally checkedout to | ||
// Jenkins Master but this will also pull this same code to this slave | ||
stage('Git Checkout') { | ||
steps { | ||
// Turn off Git's SSL cert check, uncomment if needed | ||
// sh 'git config --global http.sslVerify false' | ||
git url: "${APPLICATION_SOURCE_REPO}" | ||
} | ||
} | ||
|
||
// Run Maven build, skipping tests | ||
stage('Build'){ | ||
steps { | ||
hygieiaBuildPublishStep buildStatus: 'InProgress' | ||
sh "mvn clean install -DskipTests=true -f ${POM_FILE}" | ||
} | ||
post { | ||
failure { | ||
hygieiaBuildPublishStep buildStatus: 'Failure' | ||
} | ||
aborted { | ||
hygieiaBuildPublishStep buildStatus: 'Aborted' | ||
} | ||
success { | ||
hygieiaBuildPublishStep buildStatus: 'Success' | ||
hygieiaArtifactPublishStep artifactDirectory: './target/', artifactGroup: 'org.test', artifactName: "shift-rest-0.1.0.jar", artifactVersion: "${env.commit}-${BUILD_NUMBER}" | ||
} | ||
} | ||
} | ||
|
||
// Run Maven unit tests | ||
stage('Unit Test'){ | ||
steps { | ||
sh "mvn test -f ${POM_FILE}" | ||
} | ||
} | ||
|
||
// Build Container Image using the artifacts produced in previous stages | ||
stage('Build Container Image'){ | ||
steps { | ||
// Copy the resulting artifacts into common directory | ||
sh """ | ||
ls target/* | ||
rm -rf oc-build && mkdir -p oc-build/deployments | ||
for t in \$(echo "jar;war;ear" | tr ";" "\\n"); do | ||
cp -rfv ./target/*.\$t oc-build/deployments/ 2> /dev/null || echo "No \$t files" | ||
done | ||
""" | ||
|
||
// Build container image using local Openshift cluster | ||
// Giving all the artifacts to OpenShift Binary Build | ||
// This places your artifacts into right location inside your S2I image | ||
// if the S2I image supports it. | ||
binaryBuild(projectName: env.BUILD, buildConfigName: env.APP_NAME, artifactsDirectoryName: "oc-build") | ||
} | ||
} | ||
|
||
stage('Promote from Build to Dev') { | ||
steps { | ||
tagImage(sourceImageName: env.APP_NAME, sourceImagePath: env.BUILD, toImagePath: env.DEV) | ||
} | ||
} | ||
|
||
stage ('Verify Deployment to Dev') { | ||
steps { | ||
verifyDeployment(projectName: env.DEV, targetApp: env.APP_NAME) | ||
} | ||
post { | ||
success { | ||
hygieiaDeployPublishStep applicationName: "${APP_NAME}", artifactDirectory: './target/', artifactGroup: 'org.test', artifactName: "shift-rest-0.1.0.jar", artifactVersion: "${env.commit}-${BUILD_NUMBER}", buildStatus: 'Success', environmentName: "${env.DEV}" | ||
} | ||
} | ||
} | ||
|
||
stage('Promote from Dev to Stage') { | ||
steps { | ||
tagImage(sourceImageName: env.APP_NAME, sourceImagePath: env.DEV, toImagePath: env.STAGE) | ||
} | ||
} | ||
|
||
stage ('Verify Deployment to Stage') { | ||
steps { | ||
verifyDeployment(projectName: env.STAGE, targetApp: env.APP_NAME) | ||
} | ||
post { | ||
success { | ||
hygieiaDeployPublishStep applicationName: "${APP_NAME}", artifactDirectory: './target/', artifactGroup: 'org.test', artifactName: "shift-rest-0.1.0.jar", artifactVersion: "${env.commit}-${BUILD_NUMBER}", buildStatus: 'Success', environmentName: "${env.STAGE}" | ||
} | ||
} | ||
} | ||
|
||
stage('Promotion gate') { | ||
steps { | ||
script { | ||
input message: 'Promote application to Production?' | ||
} | ||
} | ||
} | ||
|
||
stage('Promote from Stage to Prod') { | ||
steps { | ||
tagImage(sourceImageName: env.APP_NAME, sourceImagePath: env.STAGE, toImagePath: env.PROD) | ||
} | ||
} | ||
|
||
stage ('Verify Deployment to Prod') { | ||
steps { | ||
verifyDeployment(projectName: env.PROD, targetApp: env.APP_NAME) | ||
} | ||
post { | ||
success { | ||
hygieiaDeployPublishStep applicationName: "${APP_NAME}", artifactDirectory: './target/', artifactGroup: 'org.test', artifactName: "shift-rest-0.1.0.jar", artifactVersion: "${env.commit}-${BUILD_NUMBER}", buildStatus: 'Success', environmentName: "${env.PROD}" | ||
} | ||
} | ||
} | ||
} | ||
} |