Reputation: 305
I am using a gitlab for my project where I am defining an environment variable inside "Settings->CI/CD->Environment variables" and initializing value of it as "0". Now as part of CI pipeline, I want to modify the value of this environment variable and want to increase by 1. I am trying to do this in my gulp file:
gulp.task('incrementBuildId', function()
{
process.env.BUILD_ID = buildId + 1;
});
However the value of environment variable isn't getting changed. Am I doing anything wrong here? Is there any other way to have a global environment variable and keep changing it's value?
Upvotes: 4
Views: 6085
Reputation: 872
As of now, there is no way to modify gitlab environment variable to persist. However, you could look for any vault
or api-server to do the same.
Option 1: (Recommended)
For your case, if I'm not wrong you want to set the build ID as last build ID +1
for that purpose gitlab allows a pipeline to commit to a specific branch, so you could have the pipeline read a file which contains the last build ID and then set the current build ID as last build ID+1
then commit it to branch and repeat the process for every build.
CI_COMMIT_SHA: is unique per commit CI_PIPELINE_ID: is Unique per pipeline CI_JOB_ID: is unique per Pipeline
So, You could use - CI_PIPELINE_ID + CI_JOB_ID - CI_COMMIT_SHA + CI_JOB_ID
This will produce unique values even if you run the same pipeline (CI) again and again.
Option 2:
However, I would recommend you give the build ID as the pipeline ID (known as CI_PIPELINE_ID) which is unique. example,
build_id = v1.0.${CI_PIPELINE_ID} #during build phase
#if current pipeline id = 3000, then build_id will be v1.0.3000
You may find the variables available with gitlab here. Some variables are unique like CI_JOB_ID
, CI_COMMIT_SHA
, CI_PIPELINE_ID
etc., (for gitlab v9.0+).
Upvotes: 2