Set environment variables for each workflow in a stage

Is it possible to set environment variables for a workflow within a stage? e.g.

stages:
  test:
    workflows:
    - all_tests: {}
  build:
    workflows:
    - single_scheme: {
      flavour: production
    }
    - single_scheme: {
      flavour: staging
    }
2 Likes

Hey @lukewakefordpassenge

Thanks for posting your question!

Yes, it is possible to set environment variables for a workflow within a stage.
Add the following code to the bitrise.yml file:

format_version: 1.3.1
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git

stages:
  test:
    workflows:
      - all_tests: {}
  build:
    workflows:
      - single_scheme:
          flavour: production
      - single_scheme:
          flavour: staging

Next, add the environment variables to the workflows. For example:

format_version: 1.3.1
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git

stages:
  test:
    workflows:
      - all_tests:
          envs:
            - ENV_VAR_ONE: first value
            - ENV_VAR_TWO: second value
  build:
    workflows:
      - single_scheme:
          flavour: production
          envs:
            - ENV_VAR_ONE: first value
            - ENV_VAR_TWO: second value
      - single_scheme:
          flavour: staging
          envs:
            - ENV_VAR_ONE: first value
            - ENV_VAR_TWO: second value

Save the bitrise.yml file.

Run the bitrise command to execute the workflows:

bitrise run all_tests 
bitrise run single_scheme:production 
bitrise run single_scheme:staging

Please let us know if this helped or if you need further assistance.

Thanks again,
Leilah

1 Like

Hey thanks for the pointers.

Is it possible to run the whole pipeline or an individual stage from the cli? e.g.

bitrise run test or bitrise run build ?

Right now these commands error with:

specified Workflow (test) does not exist

Yes, it is possible to run the whole pipeline or an individual stage from the Bitrise CLI.

Typically to run an individual stage, you need to specify the Workflow ID in the bitrise run command: bitrise run <WORKFLOWID>

Before doing that though, can you make sure that the Workflow ID is correctly specified in the bitrise.yml file. The Workflow ID should match the ID of the Workflow you are trying to run.

Now to further troubleshoot the error:

  1. Check the bitrise.yml file to make sure the Workflow with the name ‘test’ exists.

  2. If the Workflow exists, check the configuration of the Workflow to make sure it is set up correctly. This includes checking the Step names, Step inputs, Step outputs, Environment Variables, and other configurations are correctly specified.

Please let me know if this was helpful or if you need additional assistance.

Thanks again,
Leilah

This isn’t working for me when trying to add an env var to workflow in a stage. See an example of my yaml file here:

stages:
  install:
    workflows:
    - install_node_modules: {}
  build_platforms:
    workflows:
    - deploy_android_staging: {}
    - deploy_ios_staging:
        envs:
          - IOS_DISTRIBUTION_METHOD: ad-hoc

I’m also seeing a lint error as well when adding envs to a workflow in a stage. Any idea what’s going on here?

1 Like

Hi! Specifying stage-specific environment variables on workflows in pipelines is currently not supported.

Hello, currently I have my pipeline configured like this,
However my env is never passed to the workflow. Is there any option? Or I should create all workflows differently?

I also have this issue when trying to add envs:
Screenshot 2023-09-22 at 11.36.55

pipelines:
  pipeline-test-end-to-end:
    stages:
      - stage-build-end-to-end: {}
      - stage-test-end-to-end: {}

stages:
  stage-build-end-to-end:
    workflows:
      - workflow-build-e2e-android: {}
  stage-test-end-to-end:
    workflows:
      - workflow-test-e2e-android:
          envs:
            - TEST_TAG: tag-part-1
      - workflow-test-e2e-android:
          envs:
            - TEST_TAG: tag-part-2
1 Like

pilvikala Do you know if this feature will become available anytime soon? Thanks!

@erickriseup Apologies, I am not with Bitrise anymore, so I don’t have that information.

@viktorbenei ?