skip to Main Content

I recently started working on using some GitHub actions on my projects. I am able to setup them up to run automatically but am struggling with having them run manually. I know that you need the have the workflow_dispatch in the on section. I’m not sure if it’s not working because I have it automatically run too. Is someone able to tell me what I am doing wrong?

Here is one of my workflow YAML files

name: Create-Doc-Nightly

on:  
  push:
    branches: [ "nightly" ]
    paths:
      - 'src/**'
      - 'pom.xml'
 
  workflow_dispatch:

jobs:
  doc:
    name: Create Doc
    runs-on: ubuntu-latest
    
    steps:
      - uses: actions/checkout@v3
        name: Step 1 - Checkout Nightly Branch
        with:
          persist-credentials: false
          fetch-depth: 0
      - name: Step 2 - Setup JDK 17
        uses: actions/[email protected]
        with: 
          java-version: 17
          distribution: 'temurin'
      - name: Step 3 - Remove Doc
        run: |
          git remote set-url origin https://jnstockley:${{ secrets.TOKEN }}@github.com/jnstockley/BTTN.git
          git config user.email "[email protected]"
          git config --local user.name "Jack Stockley"
          git rm -r docs
          git commit -m "Removed Docs"
          git push origin nightly
      - name: Step 4 - Create Doc
        run: mvn dokka:dokka -f pom.xml
      - name: Step 5 - Move Docs
        run: |
           rm -rf docs
           mkdir -p docs
           mv target/dokka/* docs
      - name: Step 6 - Publish docs
        run: |
          git remote set-url origin https://jnstockley:${{ secrets.TOKEN }}@github.com/jnstockley/BTTN.git
          git config user.email "[email protected]"
          git config --local user.name "Jack Stockley"
          git add -f docs
          git commit -m "Updated Docs"
          git push origin nightly

Link to GitHub repo, nightly branch: https://github.com/jnstockley/BTTN/tree/nightly

2

Answers


  1. The workflow must be on your default branch in order to use workflow_dispatch.

    I believe in your case it’s only on the branch nightly while it should also be on main.

    Login or Signup to reply.
  2. To manually trigger a workflow, use the workflow_dispatch event. You can manually trigger a workflow run using the GitHub API, GitHub CLI, or GitHub browser interface. For more information, see Manually running a workflow

    on: workflow_dispatch
    

    Providing inputs

    You can configure custom-defined input properties, default input values, and required inputs for the event directly in your workflow. When you trigger the event, you can provide the ref and any inputs. When the workflow runs, you can access the input values in the inputs context. For more information, see Contexts

    This example defines inputs called logLevel, tags, and environment. You pass values for these inputs to the workflow when you run it. This workflow then prints the values to the log, using the inputs.logLevel, inputs.tags, and inputs.environment context properties.

    yaml

    on:
      workflow_dispatch:
        inputs:
          logLevel:
            description: 'Log level'
            required: true
            default: 'warning'
            type: choice
            options:
            - info
            - warning
            - debug
          tags:
            description: 'Test scenario tags'
            required: false
            type: boolean
          environment:
            description: 'Environment to run tests against'
            type: environment
            required: true
    
    jobs:
      log-the-inputs:
        runs-on: ubuntu-latest
        steps:
          - run: |
              echo "Log level: $LEVEL"
              echo "Tags: $TAGS"
              echo "Environment: $ENVIRONMENT"
            env:
              LEVEL: ${{ inputs.logLevel }}
              TAGS: ${{ inputs.tags }}
              ENVIRONMENT: ${{ inputs.environment }}
    

    If you run this workflow from a browser you must enter values for the required inputs manually before the workflow will run.

    enter image description here

    You might like the following documentation links

    workflow_dispatch

    github docs – events-that-trigger-workflows

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search