E
E
Evgeny2019-02-20 15:16:55
GitLab
Evgeny, 2019-02-20 15:16:55

Why doesn't Gitlab push variables to all branches?

I created and configured gitlab ci, added variables to the gitlab interface. I'm trying
to make different build settings for different branches.
However, I ran into the fact that when the build occurs on all branches except master, the build does not receive environment variables.

image: docker:stable
services:
  - docker:dind

stages:
  - test
  - package

variables:
  DOCKER_HOST: tcp://dockerhost
  DOCKER_TLS_VERIFY: 1
  DOCKER_CERT_PATH: "/certificates"

before_script:
  - mkdir -p $DOCKER_CERT_PATH
  - echo "$TLSCACERT" > $DOCKER_CERT_PATH/ca.pem
  - echo "$TLSCERT" > $DOCKER_CERT_PATH/cert.pem
  - echo "$TLSKEY" > $DOCKER_CERT_PATH/key.pem
  - echo $HUB_REGISTRY_PASSWORD
  - echo $TLSCACERT
  - cat $DOCKER_CERT_PATH/ca.pem
  - docker login -u derbenev -p $HUB_REGISTRY_PASSWORD $CI_REGISTRY

test:
  stage: test
  only:
    - develop
    - master
    - prod
  tags:
    - docker
  script:
    - pwd
    - sh test.sh

develop:
  stage: package
  only:
    - develop
  tags:
    - docker
  script:
    - build.sh

When building from the master branch, I see the specified environment variables
$ cat $DOCKER_CERT_PATH/ca.pem
-----BEGIN CERTIFICATE----- **** -----END CERTIFICATE-----
$ docker login -u derbenev -p $HUB_REGISTRY_PASSWORD $CI_REGISTRY
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
$ echo $HUB_REGISTRY_PASSWORD
***
$ echo $TLSCACERT
-----BEGIN CERTIFICATE----- *** --END CERTIFICATE-----

and when building from other branches, it gives
$ echo $HUB_REGISTRY_PASSWORD

$ echo $TLSCACERT

$ cat $DOCKER_CERT_PATH/ca.pem

$ docker login $CI_REGISTRY
failed to append certificates from PEM file: "/certificates/ca.pem"

I can't figure out what's wrong

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny, 2019-02-22
Lubyanoy @arswarog

I found out that for this the branch must be in the list of protected

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question