C
C
Capablanca2020-02-21 13:23:02
GitLab
Capablanca, 2020-02-21 13:23:02

How to pass variables from gitlab-ci.yml to React?

Hello! I have a typescript application on react.

I create custom variables during the build process on gitlab, using gitlab's predefined variable, including, then I need to transfer the result to React. Here is what I have written so far.

gitlab-ci.yml

build:
  stage: build
  only:
    - develop
  script: |
    export BRANCH=$CI_COMMIT_BRANCH
    export TIMESTAMP=$(date +%d%m%Y.%H%M)
    npm run build --env.BRANCH=$BRANCH --env.BUILDTIME:$TIMESTAMP


this is webpack:
new webpack.DefinePlugin({
        'process.env.BRANCH': JSON.stringify(process.env.BRANCH),
        'process.env.BUILD_TIME': JSON.stringify(process.env.BUILDTIME),
      })


Next, I bind process.env.BUILD_TIME to window through a script call in the application. And after that on a live stand I get undefined. I can't figure out what's wrong

1) Is it even possible to create my own variables the way I did in the gitlab-ci.yml process? If not, how is it right?
2) my webpack.config now has such an initialization
module.exports = env =>
. That is, where do I declare to the webpack what NON-DEFAULT variables it should accept?
Where should they be declared and assigned a value?
That is, I'm not talking about variables with a value that can be set in the gitlab interface, but these are dynamic ones that should be made during the build process on gitlab

Help, please: 3

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question