Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Pages Test
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Operate
Environments
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitLab Tests
Pages Test
Commits
69bf05a0
Commit
69bf05a0
authored
2 years ago
by
Chris Coley
Browse files
Options
Downloads
Plain Diff
Merge branch 'variable-substitution' into 'variable-substitution'
Variable substitution See merge request
!5
parents
36554c45
d5360dcd
No related branches found
No related tags found
1 merge request
!5
Variable substitution
Pipeline
#630
passed
2 years ago
Stage: .pre
Stage: deploy
Changes
1
Pipelines
2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
.gitlab-ci.yml
+28
-5
28 additions, 5 deletions
.gitlab-ci.yml
with
28 additions
and
5 deletions
.gitlab-ci.yml
+
28
−
5
View file @
69bf05a0
...
@@ -5,15 +5,38 @@ workflow:
...
@@ -5,15 +5,38 @@ workflow:
rules
:
rules
:
-
if
:
$CI_COMMIT_BRANCH
-
if
:
$CI_COMMIT_BRANCH
# We can't do variable substitution in a job and then also use that computed
# variable in the Environment URL of the same job, so we have to do the
# substitution in an earlier stage. All of this variable substitution is only
# required for projects in sub-groups because GitLab doesn't have a predefined
# variable that contains the project namespace relative to the root namespace.
#
# For example, if the project path is "/group/subgroup-1" then we need just the
# "/subgroup-1" portion because that is used in the Environment URL path, while
# the "/group" root namespace is used as the subdomain.
setup
:
stage
:
.pre
tags
:
-
docker
script
:
-
echo "ROOT_RELATIVE_NAMESPACE=${CI_PROJECT_NAMESPACE#$CI_PROJECT_ROOT_NAMESPACE}" >> build.env
artifacts
:
reports
:
dotenv
:
build.env
# We can't deploy multiple different variants of GitLab Pages sites (e.g. one
# We can't deploy multiple different variants of GitLab Pages sites (e.g. one
# per branch), so we use this
quick
instead. GitLab has a special browsable
URL
# per branch), so we use this
workaround
instead. GitLab has a special browsable
# for job artifacts on public projects, and we can create an Environment
that
#
URL
for job artifacts on public projects, and we can create an Environment
# points to that URL so it's easy for devs to know what the current
Environment
#
that
points to that URL so it's easy for devs to know what the current
# URL for their branch is.
#
Environment
URL for their branch is.
.deploy
:
.deploy
:
stage
:
deploy
stage
:
deploy
tags
:
tags
:
-
docker
-
docker
before_script
:
-
echo $CI_ENVIRONMENT_URL
-
echo $ROOT_RELATIVE_NAMESPACE
-
test "$ROOT_RELATIVE_NAMESPACE" == "${CI_PROJECT_NAMESPACE#$CI_PROJECT_ROOT_NAMESPACE}" || { echo "ROOT_RELATIVE_NAMESPACE is not set correctly" ; exit 1 ; }
script
:
script
:
-
sed -i "s/%%BRANCH%%/$CI_COMMIT_BRANCH/g" src/index.html
-
sed -i "s/%%BRANCH%%/$CI_COMMIT_BRANCH/g" src/index.html
-
mv src public
-
mv src public
...
@@ -29,7 +52,7 @@ review:
...
@@ -29,7 +52,7 @@ review:
-
if
:
$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
-
if
:
$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
environment
:
environment
:
name
:
"
review
$CI_COMMIT_BRANCH"
name
:
"
review
$CI_COMMIT_BRANCH"
url
:
"
https://$CI_PROJECT_NAMESPACE.$CI_PAGES_DOMAIN/-/$CI_PROJECT_NAME/-/jobs/$CI_JOB_ID/artifacts/public/index.html"
url
:
"
https://$
{
CI_PROJECT_
ROOT_
NAMESPACE
}
.$
{
CI_PAGES_DOMAIN
}
/-
${ROOT_RELATIVE_NAMESPACE}
/$
{
CI_PROJECT_NAME
}
/-/jobs/$CI_JOB_ID/artifacts/public/index.html"
# Deploy to GitLab Pages for pushes on the default branch
# Deploy to GitLab Pages for pushes on the default branch
pages
:
pages
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment