0

I'd like to parameterize the environment URL of one of my GitLab CI job in a project which belongs to a subgroup.

If for example I have:

CI_PROJECT_PATH = mygroup/mysubgroup/myproject
CI_PROJECT_NAMESPACE = mygroup/mysubgroup
CI_PROJECT_NAME = myproject

I'd like to have the URL to be something like https://mygroup.gitlab.com/-/mysubgroup/myproject/-/jobs/12345/artifacts/public/index.html.

But I cannot find a way to do this since there is no predefined variable for the "sub-namespace" (here mysubgroup) and there is no variable substitution in environment.url as far as I can see.

I tried in my gitlab-ci.yml things like that:

build:
  stage: build
  image: bash:latest
  script:
    - export # print the available variables
  environment:
    name: test
    url: ${CI_SERVER_PROTOCOL}://${CI_PROJECT_ROOT_NAMESPACE}.${CI_PAGES_DOMAIN}/-/${CI_PROJECT_PATH#${CI_PROJECT_ROOT_NAMESPACE}/}/-/jobs/$CI_JOB_ID/artifacts/public/index.html

but the result is https://mygroup.gitlab.com/-/${CI_PROJECT_PATH#myproject/}/-/jobs/12345/artifacts/public/index.html.

References:

ddidier
  • 1,298
  • 1
  • 12
  • 15

2 Answers2

0

I think you need to escape the inner curly braces like this: (${CI_PROJECT_ROOT_NAMESPACE} should become $`{CI_PROJECT_ROOT_NAMESPACE`})

So the whole thing becomes:

url: ${CI_SERVER_PROTOCOL}://${CI_PROJECT_ROOT_NAMESPACE}.${CI_PAGES_DOMAIN}/-/${CI_PROJECT_PATH#$`{CI_PROJECT_ROOT_NAMESPACE`}/}/-/jobs/$CI_JOB_ID/artifacts/public/index.html

d-g
  • 21
  • 3
0

job:environment:url is directly processed by gitlab, which does not support this kind of parameter expansion.

You'll need to use bash or a similar shell for this to work as intended:

build:
  stage: build
  image: bash:latest
  script:
    - echo "DEPLOY_URL=${CI_SERVER_PROTOCOL}://${CI_PROJECT_ROOT_NAMESPACE}.${CI_PAGES_DOMAIN}/-/${CI_PROJECT_PATH#${CI_PROJECT_ROOT_NAMESPACE}/}/-/jobs/$CI_JOB_ID/artifacts/public/index.html" > deploy.env
    - cat deploy.env
  artifacts:
    reports:
      dotenv: deploy.env
  environment:
    name: test
    url: $DEPLOY_URL

Based on the example given here: https://docs.gitlab.com/ee/ci/environments/#example-of-setting-dynamic-environment-urls

DaDummy
  • 64
  • 3