Can I determine the current branch from gradle in github actions?

467 Views Asked by At

I'm adding some logic to a gradle task based on the current branch that I'm working on. So the workflow should be:

  1. Checkout the repository
  2. Execute a gradle task which has something like the following:
task getCurrentWorkingBranch {
  def currentBranch = 'git branch --show-current'.execute().text.trim()
  logger.info('The current branch is ' + currentBranch)
  
  if (currentBranch.equals('main')) {
    // do some stuff here
  }
}

My github action workflow would be something like

steps:
  - name: Checkout 
    uses: actions/checkout@v2
  - name: Setup Tools 
    uses: actions/[email protected]
    with: 
      java-version: 11.0.9
      java-package: jdk
  - name: Gradles permissions          
    run: chmod +x gradlew
  - name: Get current branch
    run: ./gradlew getCurrentWorkingBranch --debug

The out from the github actions logs are:

2020-12-16T15:41:50.474+0000 [INFO] [org.gradle.api.Task] The current branch is

So it doesn't look like gradle can determine the branch that was just checked out in github actions?

0

There are 0 best solutions below