PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, August 21, 2022

[FIXED] How to pass environment variables into .gitlab-ci.yml in Gitlab for Spring Boot?

 August 21, 2022     continuous-integration, environment-variables, gitlab, spring-boot     No comments   

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 - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing