0

Working on Github actions for the first time. In my .yml file I have the following

on:
  workflow_dispatch:
    branches:    
      - main
    inputs:
      environment:
        type: choice
        description: 'Select environment to deploy in'
        required: true
        options:
          - dev
          - non-prod
          - prod
          - staging

based on the option I need to do the following

for staging

  - name: build
    run: CI=false yarn build-staging

for non-prod

  - name: build
    run: CI=false yarn build

Could you please provide me with some pointers on how this can be achieved?

1 Answer 1

2

The simplest way to go about it would be to use an if condition on the jobs within your workflow, for example:

on:
  workflow_dispatch:
    branches:    
      - main
    inputs:
      environment:
        type: choice
        description: 'Select environment to deploy in'
        required: true
        options:
          - dev
          - non-prod
          - prod
          - staging
jobs:
  staging:
    runs-on: ubuntu-latest
    if: inputs.environment == 'staging'
    steps:
    - name: build
      run: CI=false yarn build-staging
  prod:
    runs-on: ubuntu-latest
    if: inputs.environment == 'prod'
    steps:
    - name: build
      run: CI=false yarn build
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.