How to set specific workspace folder for jenkins multibranch pipeline projects

后端 未结 1 1054
时光取名叫无心
时光取名叫无心 2020-12-31 04:01

I have an external tool that should be called as build-step in one of my jenkins jobs. Unfortunately, this tool has some issues with quoting commands to avoid problems with

相关标签:
1条回答
  • 2020-12-31 04:40

    the ws instruction sets the workspace for the commands inside it. for declarative pipelines, it's like this:

    ws("C:\jenkins") {
      echo "awesome commands here instead of echo"
    }
    

    You can also call a script to build the customWorkspace to use:

    # if the current branch is master, this helpfully sets your workspace to /tmp/ma
    partOfBranch = sh(returnStdout: true, script: 'echo $BRANCH_NAME | sed -e "s/ster//g"')
    path = "/tmp/${partOfBranch}"
    sh "mkdir ${path}"
    ws(path) {
      sh "pwd"
    }
    

    you can also set it globally by using the agent block (generally at the top of the pipeline block), by applying it to a node at that level:

    pipeline {
      agent {
        node {
          label 'my-defined-label'
          customWorkspace '/some/other/path'
        }
      }
      stages {
        stage('Example Build') {
          steps {
            sh 'mvn -B clean verify'
          }
        }
      }
    }
    

    Another node instruction later on might override it. Search for customWorkspace at https://jenkins.io/doc/book/pipeline/syntax/. You can also it use it with the docker and dockerfile instructions.

    0 讨论(0)
提交回复
热议问题