【问题标题】:Is there a way to add pre-build step for Jenkins pipeline?有没有办法为 Jenkins 管道添加预构建步骤?
【发布时间】:2018-03-04 19:28:15
【问题描述】:

目前我可以在我的 Jenkinsfile 中使用 post 指令。有没有办法触发与此类似的预构建步骤?

  post {
    always {
      sh '''rm -rf build/workspace'''
    }
  }

【问题讨论】:

标签: jenkins jenkins-pipeline pre-build-event prebuild


【解决方案1】:

我相信这个较新的问题可能有答案:Is there a way to run a pre-checkout step in declarative Jenkins pipelines?

pre 是一个很酷的功能创意,但还不存在。跳过默认结账 和 checkout scm(与默认结帐相同)是 键:

pipeline {
  agent { label 'docker' }
  options {
    skipDefaultCheckout true
  }
  stages {
    stage('clean_workspace_and_checkout_source') {
      steps {
        deleteDir()
        checkout scm
      }
    }
    stage('build') {
      steps {
        echo 'i build therefore i am'
      }
    }
  }
}

【讨论】:

  • 我正在寻找相同的概念。但是这里的问题是我想执行一个任务,即使以前的代理 docker 是在主服务器上设置的。使用这种方法,“预任务”将在 docker 中运行
  • 您应该能够使用 node('master') { steps { doSomething() } } 在单独的节点上为某些步骤声明操作
猜你喜欢
  • 2018-01-03
  • 2017-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多