Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!groovy
- /* Sample structure for optional parametrized DDSL pipeline steps
- * Copyright (C) 2016 by Jim Klimov on the terms of MIT license
- */
- pipeline {
- agent label:"myproject-builder"
- parameters {
- booleanParam(defaultValue: false, description: 'Removes workspace completely before checkout and build', name: 'action_DistcleanRebuild')
- booleanParam(defaultValue: false, description: 'Wipes untracked files from workspace before checkout and build', name: 'action_GitcleanRebuild')
- booleanParam(defaultValue: true, description: 'Run Git to checkout or update the project sources', name: 'action_DoSCM')
- /* other boolean toggles and/or string parameter definitions for prep, build, check, publish, etc. stages and other behaviors */
- }
- stages {
- stage("WORKSPACE:DESTROY") {
- when {
- if (params["action_DistcleanRebuild"] == true) {
- if (fileExists(file: "${env.WORKSPACE}/.git/config")) {
- return true;
- }
- }
- return false;
- }
- steps {
- echo "Removing '${env.WORKSPACE}' at '${env.NODE_NAME}'"
- dir("${env.WORKSPACE}") {
- deleteDir()
- }
- }
- }
- stage("WORKSPACE:GITWIPE") {
- when {
- if (params["action_DistcleanRebuild"] == false && params["action_GitcleanRebuild"] == true) {
- if (fileExists(file: "${env.WORKSPACE}/.git/config")) {
- return true;
- }
- }
- return false;
- }
- steps {
- dir("${env.WORKSPACE}") {
- echo "Git-cleaning '${env.WORKSPACE}' at '${env.NODE_NAME}'"
- sh 'git checkout -f'
- sh 'git clean -d -ff -x'
- }
- }
- post {
- failure {
- echo "ERROR: Git clean failed in '${env.WORKSPACE}' at '${env.NODE_NAME}', removing workspace completely"
- dir("${env.WORKSPACE}") {
- deleteDir()
- }
- }
- }
- }
- stage("WORKSPACE:CHECKOUT") {
- when {
- params["action_DoSCM"] == true
- }
- steps {
- sh "mkdir -p '${env.WORKSPACE}'"
- checkout scm
- }
- }
- /* other stages for prep, build, check, publish, etc. */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement