Issue
I have setup the application.properties
the following:
spring.datasource.url=jdbc:postgresql://${SERVER_IP}/database
spring.datasource.username=${POSTGRES_USER}
spring.datasource.password=${POSTGRES_PASSWORD}
spring.datasource.driver-class-name=org.postgresql.Driver
To be able to package the application, the environment variables has to be passed into the Maven command something like that:
mvn -DSERVER_IP=111.111.11.1111:5432 -DPOSTGRES_USER=user -DPOSTGRES_PASSWORD="password" package
In the .gitlab-ci.yml, I need to pass in these environment variables
maven-build:
image: maven:3-jdk-8
stage: build
script: "mvn {what should I write here?} package -B"
artifacts:
paths:
- target/*.jar
I understand that first in Gitlab's setting the environment variables has to be defined, but how should I reference those environment variables in the .gitlab-ci.yml?
Solution
Set the required Environment Variables in your Project -> Settings -> CI/CD -> Environment Variables
.
And then in the .gitlab-ci.yml
just reference them as such :
script: mvn -DSERVER_IP=$SERVER_IP -DPOSTGRES_USER=$POSTGRES_USER -DPOSTGRES_PASSWORD=$POSTGRES_PASSWORD package -B
NB: From the documentation:
Important: Be aware that variables are not masked, and their values can be shown in the job logs if explicitly asked to do so. If your project is public or internal, you can set the pipelines private from your project’s Pipelines settings. Follow the discussion in issue #13784 for masking the variables.
Answered By - Rekovni
Answer Checked By - Terry (JavaFixing Volunteer)