How to setup Gradle publish task user credentials with GitLab CI secret variables? I am using gradle maven publish plugin, and here is snippet from build.gradle
repositories {
maven {
credentials {
username artifactUser
password artifactPass
}
url "..."
}
}
I've tried to use gradle.properties
as below
artifactUser=${env.MAVEN_REPO_USER}
artifactPass=${env.MAVEN_REPO_PASS}
And several ways of accessing secret variables in .gitlab-ci.yml
file (because gradle.properties is not picked up from gradle or variables are not transformed correctly, it is in root project dir)
Method 1
'./gradlew publish -x test -PartifactUser=${env.MAVEN_REPO_USER} -PartifactPass=${env.MAVEN_REPO_PASS}'
Error: /bin/bash: line 56: -PartifactUser=${env.MAVEN_REPO_USER}: bad substitution
Method 2
before_script:
- chmod +x ./gradlew
- export REPO_USER=${env.MAVEN_REPO_USER}
- export REPO_PASS=${env.MAVEN_REPO_PASS}
...
deploy:
stage: deploy
script:
- ./gradlew publish -x test -PartifactUser=$REPO_USER -PartifactPass=$REPO_PASS
I am using openjdk:8-jdk-slim
image for build using gradle wrapper. Seems like there are several issues with this kind of variable usage, do we have any workaround?