Skip to content

Instantly share code, notes, and snippets.

@rkalit
Created July 25, 2019 07:47
Show Gist options
  • Select an option

  • Save rkalit/98c22cfcaf6111886c91849a59764326 to your computer and use it in GitHub Desktop.

Select an option

Save rkalit/98c22cfcaf6111886c91849a59764326 to your computer and use it in GitHub Desktop.
example of my pipeline
def buildStatus = false
def testStatus = false
pipeline {
agent any
stages {
stage('Checkout branch') {
parallel {
stage('Checkout branch') {
steps {
echo 'checkout scm'
}
}
stage('Prepare ENV') {
steps {
echo 'Environment Setting'
}
}
}
}
stage ('Build & Test') {
parallel {
stage('Build') {
steps {
script {
try {
echo "Build Stage"
buildStatus = true
} catch (Exception err) {
buildStatus = false
}
}
}
}
stage('Test') {
steps {
script {
try {
echo "Test Stage"
testStatus = true
} catch(Exception err) {
testStatus = false
}
}
}
}
}
}
stage('Send Report') {
when {
expression {
!buildStatus || !testStatus
}
}
steps {
script {
if (buildStatus) {
echo 'Put some action in here...'
} else if (testStatus){
echo 'Put some action in here...'
} else {
echo 'Put some action in here...'
}
}
}
}
stage ('Packaging and Build Image') {
when {
expression {
buildStatus && testStatus
}
}
parallel {
stage('Build and push docker image') {
steps {
script {
echo "Dockerize Stage"
}
}
}
stage('Packaging Jar to tgz and save to alibaba') {
steps {
script {
echo "Packaging Stage"
}
}
}
}
}
stage ('Deploy Feature/Alpha') {
when {
expression {
buildStatus && testStatus
}
}
steps {
script {
echo "This stage is underconstruction"
try {
echo "Run the command to Deploy feature/alpha"
try {
timeout(time: 1, unit: 'DAYS') {
env.userChoice = input message: 'Do you want to Release?',
parameters: [choice(name: 'Versioning Service', choices: 'no\nyes', description: 'Choose "yes" if you want to release this build')]
}
if (userChoice == 'no') {
echo "User refuse to release this build, stopping...."
} else {
deployStatus = true
}
} catch (Exception err) {
echo "Send notification to Slack that the operation has been aborted"
}
} catch (Exception err) {
echo "Will fail and send the report"
}
}
}
}
stage ('Release Build') {
when {
environment name: 'userChoice', value: 'yes'
}
steps {
script {
try {
timeout(time: 1, unit: 'DAYS') {
versionName = input (
id: 'version', message: 'Input version name', parameters: [
[$class: 'TextParameterDefinition', description: 'Whatever you type here will be your version', name: 'Version']
]
)
}
echo "the version will be: ${versionName}"
} catch (Exception err) {
echo "Send the notification to Slack that the operation has been canceled"
}
}
}
}
}
environment {
service_name = "${JOB_NAME}".split('/').first()
// put yor environment in here
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment