简体   繁体   中英

AWS CodeBuild Batch configuration not passing environment variables

I am trying to use the CodeBuild Batch configuration feature to trigger 2 different build from the same repository. For the 2 build commands, only some parameters differ which I am trying to manage through environment variables, below is the buildSpec file.

version: 0.2
batch:
  fast-fail: true
  build-list:
    - identifier: build1
      buildspec: buildspec1.yml
      env:
        variables:
          BUILD_ID:  build1ID
          privileged-mode: true
          PROJECT: Projectvalue
      ignore-failure: false
    - identifier: evaluator-build
      buildspec: buildspecs2.yml
      env:
        variables:
          BUILD_ID: build2ID
          PROJECT: ProjectValueTwo
      ignore-failure: false

phases:
  build:
    commands:
    - echo Build started on `date`
    - sbt clean
    - sbt 'project $PROJECT' 'compile'

Here Project is one of the variables I am trying to pass between the 2 builds, but the actual value is not being passed. I tried echoing the value for it but comes out as blank.

What could be wrong here? Also, is the batch config feature use correct here?

I had this problem too. The batch configuration block is only used in batch builds, not in single builds.

You can run batch builds either using 'build with overrides' or configured via a webhook then selecting batch rather than single . Once I switched to this then it worked as expected for me with environment variables being inserted.

Please note you need to add a 'batch configuration' for your CodeBuild project before this will work: https://docs.aws.amazon.com/codebuild/latest/userguide/create-project-console.html#create-project-console-batch-config

If you don't have a batch configuration then a webhook-triggered build seems to silently fail but you do get an error if you try to run a batch build from 'build with overrides'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM