无法在JenkinsFile脚本中使用变更集

时间:2019-12-09 15:10:23

标签: jenkins groovy

我的jenkinsfile脚本中的步骤有问题。我正在尝试使用changeset来确定文件的特定集合是否已更改,因为我只想在某些文件被更改时才进行构建。如果文件已更改,我添加了此步骤以调用单独的构建作业。

        stage('File check') {
             when { changeset "**/files"}
             steps {
                  build 'Build and deploy'
             }
         }

但是我得到一个错误

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 5: Unknown conditional changeset. Valid conditionals are: allOf, anyOf, branch, environment, expression, not @ line 5, column 21.
                when { changeset "**/files"}

我想念什么?我的Jenkins / groovy版本有问题吗?我正在使用詹金斯版。 2.73.3。

1 个答案:

答案 0 :(得分:0)

这对我有用:

  String projectDirectory = "terraform"
  String changesetPathRegex = "**/${projectDirectory}/**"

    stage('Build Dockerfile') {
            when { changeset changesetPathRegex }
            steps {
                dir(projectDirectory) {
                    sh 'terraform plan'
                }
            }
        }

应该查看当前存储库的“ terraform”文件夹,如果发现那里有更改,请执行相应的操作。