簡體   English   中英

如何將布爾環境變量傳遞給CircleCI中的“when”步驟?

[英]How do I pass boolean Environmental Variables to a `when` step in 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討論區的相關票據。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM