我如何将布尔环境变量传递给Circleci的“何时”



我想按照

的行动做某事
commands:
  send-slack:
    parameters:
      condition:
        type: env_var_name
    steps:
      - when:
          # only send if it's true
          condition: << parameters.condition >>
          steps:
            - run: # do some stuff if it's true
jobs:
  deploy:
    steps:
      - run:
          name: Prepare Message
          command: |
            # Do Some stuff dynamically to figure out what message to send
            # and save it to success_message or failure_message
            echo "export success_message=true" >> $BASH_ENV
            echo "export failure_message=false" >> $BASH_ENV
      - send-slack:
          text: "yay"
          condition: success_message
      - send-slack:
          text: "nay"
          condition: failure_message
    ```

基于此文档,您不能将环境变量用作CircleCi的条件。这是因为当处理配置时,when逻辑是完成的(即,在作业实际运行并设置了环境变量之前(。作为替代方案,我将逻辑添加到单独的运行步骤(或相同的初始步骤(中。

jobs:
  deploy:
    steps:
      - run:
          name: Prepare Message
          command: |
            # Do Some stuff dynamically to figure out what message to send
            # and save it to success_message or failure_message
            echo "export success_message=true" >> $BASH_ENV
            echo "export failure_message=false" >> $BASH_ENV
      - run:
          name: Send Message
          command: |
            if $success_message; then 
                # Send success message
            fi 
            if $failure_message; then 
                # Send failure message
            fi 

这是Circleci讨论委员会上的相关门票。

最新更新