terraformcontinuous-integrationactioncd

Github Actions: The Job was skipped


jobs:  
  terraform_apply:
    name: "Terraform_apply"
    if: ${{ github.ref == 'refs/heads/master' && github.event.inputs.action == 'Terraform_apply' }}
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
  
terraform_destroy:
    name: "Terraform_destroy"
    if: ${{ github.ref == 'refs/heads/master' && github.event.inputs.action == 'Terraform_destroy' }}
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

This is a snippet of my code. I clicked on terraform apply ang got the error message 'The job was skipped'


Solution

  • Hello this is a working example:

    Please ensure that you're running this workflow in the master branch

    name: Terraform Conditional Workflow
    
    on:
      workflow_dispatch:
        inputs:
          action:
            description: 'Action to perform'
            required: true
            default: 'Terraform_apply'
    
    jobs:  
      terraform_apply:
        name: "Terraform_apply"
        if: ${{ github.ref == 'refs/heads/master' && github.event.inputs.action == 'Terraform_apply' }}
        runs-on: ubuntu-latest
        steps:
          - name: Checkout
            uses: actions/checkout@v4
      
      terraform_destroy:
        name: "Terraform_destroy"
        if: ${{ github.ref == 'refs/heads/master' && github.event.inputs.action == 'Terraform_destroy' }}
        runs-on: ubuntu-latest
        steps:
          - name: Checkout
            uses: actions/checkout@v4