I have implemented GITHUB workflow actions to publish my Spring Boot app to GitHub Packages.
I have followed the Github gradle ref but I'm getting 401 Unauthorized

It seems that the github action is not able to pass env variables to let gradle task to get GIT_CICD_TOKEN by using System.getenv("GIT_CICD_TOKEN") .
My followed implementations:
Step for publishing package on github packages:
- name: Publish package
uses: gradle/gradle-build-action@v2
with:
gradle-version: 8.5
arguments: Publish
env:
GIT_CICD_TOKEN: ${{ secrets.GIT_CICD_TOKEN }}
Gradle file:
plugins {
id 'maven-publish'
id 'java'
id 'org.springframework.boot' version '3.2.1'
id 'io.spring.dependency-management' version '1.1.4'
}
publishing {
repositories {
maven {
name = "GitHubPackages"
url = "https://maven.pkg.github.com/organization_name/repo_name"
credentials {
username = 'myUserName'
password = System.getenv("GIT_CICD_TOKEN")
}
}
}
publications {
maven(MavenPublication) {
artifact bootJar
groupId = 'com.xx'
artifactId = 'appName'
version = '0.0.1-XXXX-SNAPSHOT'
}
}
}
NOTE: I have tried to put token string value directly on password field and it worked fine.
Do you have any suggestions on it ?
I understood that I can use the default GITHUB variables to publish the package without using Personal Access Token.
Let me post my workflow and build.gradle file that are working fine.
Ref GITHUB defaul Variables link
GITHUB Publish-package Workflow fixed :
Link to GITHUB_TOKEN ref
REMARK on GITHUB_TOKEN and GITHUB_ACTOR
I recommended to check GITHUB_TOKEN's Workflow permissions at followed path
Action--> General --> Workflow permissions In my case
GITHUB_ACTOR The name of the person or app that initiated the workflow.
As written in the github documentation the permissions key specifies the access that the GITHUB_TOKEN secret will allow.
build.gradle 8.5 version