jenkins - 如何禁用 "build now"选项?

标签 jenkins groovy jenkins-pipeline jenkins-groovy

对于给定的脚本化管道(jenkins),管道只能通过 GitLab 的 webhook 触发

应为该管道禁用

立即构建选项。


我们可以配置 Jenkins,以禁用 jenkins 中特定管道脚本作业的Build Now选项吗?

最佳答案

编辑:这里是带有脚本化管道的解决方案:

node {
   def userIdCause = currentBuild.getBuildCauses('hudson.model.Cause$UserIdCause')
   stage("Authorize Usage") {
      if (userIdCause.size()) {
          error('Aborting Build due to manual start - thats not permitted!')
     }
    }
}

声明性管道上不使用任何额外插件的以下解决方案怎么样:

pipeline {
...
stages {

  stage ("Authorize Usage") {
      when { expression { getCause() == "USER" } }
      steps {
            currentBuild.description = 'Aborting Build due to manual start - thats not permitted!'
            error('Aborting Build due to manual start - thats not permitted!')
      }
  }
...
}

关于jenkins - 如何禁用 "build now"选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55053752/

相关文章:

jenkins - 将多个属性文件注入(inject) Jenkins 作业

groovy - 将闭包应用于 groovy 中的任意对象

jmeter 执行与之前在 Jenkins 中构建的比较

Jenkins Scripted Pipeline 将工件保留 90 天,或值(value) 10 次构建,以较大者为准

jenkins 2 加载一些插件的依赖错误

github - Jenkins + Github Pull 请求构建器显示名称

maven - 将 CodeNarc 与 Maven 结合使用

jenkins - ng build 不是在 Jenkins 中创建 Assets 等

groovy - 在 Groovy 中将关联数组转换为映射

grails - 如何从 Grails Controller 返回 404/50x 状态代码?