Codefresh variables should be always available

Codefresh provides a mechanism that allows the pipelines to retrieve variables. The normal way to do so is to use the ${{VARIABLE}} format.

I have encountered multiple times an unexpected behavior while using this format: Whenever a variable is not available it does not get replaced and the placeholder simply stays there as-is.

As an example if I try to use the variable ${{MYVARIABLE} which has not been defined, the final YAML won’t have an empty string as a replacement to the placeholder, nor will the pipeline fail because there is an undefined variable. The placeholder will simply stay there as it is.

To make things even worse, the system provided variable that I always expected to be set to some value turned out not being set in multiple occasions.

I’d like to bring as an example the CF_PULL_REQUEST_TARGET, the expected behavior is that this variable will be empty when the pipeline is manually run or the webhook event is not a pull request. The result instead is that the variable is not available and the placeholder doesn’t get replaced.

This behavior is also inconsistent with the normal behavior of the dollar $ in UNIX systems (e.g. echo $MYVARIABLE) used to access environment variables.

Hello

I passed your feedback to our dev team and they agree completely. We created an internal feature request and will plan soon.

1 Like

Thank you very much!

As a side note, I think that undefined variables should just return a warning - and maybe a “strict mode” could be optionally enabled to force undefined variables to generate an error.

A strict mode could be used, of course, for other purposes as well.

Any update on this? I get bit by the placeholder getting used as the default value quite often. Making this more standard (empty string, or offer a default set mechanism) would be great.

Hello

We have been discussing this issue internally for a long time. We agree that the requested behavior makes more sense. However, changing that now will break all existing pipelines for all customers. So it is a tradeoff between convenience and backwards compatibility.

Stay tuned, we have a possible solution in the works.

We have any insigns or update on this issue?

right now my solution is create an step that read actually the property and set another variable and pass what to subsecuent pipelines.

setting_PR_vars:
    title: "settings pr vars" 
    image: xxxx
    stage: "xxxx"
 
    commands:
      - echo ${{CF_PULL_REQUEST_ACTION}}
      - cf_export CF_PULL_REQUEST_ACTION_PIPELINE=${{CF_PULL_REQUEST_ACTION}}
    when:
      condition:
        all:
          prActionOpen: '"${{CF_PULL_REQUEST_ACTION}}" == "opened"'

and then catch using on the next pipeline :

      VARIABLE:
        - CF_PULL_REQUEST_ACTION=${{CF_PULL_REQUEST_ACTION_PIPELINE}}

Hey Jose

Unfortunately no ETA yet.

I will update this thread when we have something solid.

1 Like