Как передать логические переменные среды в шаг `когда` в CircleCI? - PullRequest
0 голосов
/ 23 мая 2019

Я хочу сделать что-то вроде

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
    ```

1 Ответ

0 голосов
/ 24 мая 2019

На основании этой документации вы не можете использовать переменные среды в качестве условий в 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.

...