Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
925b7410
Commit
925b7410
authored
Oct 06, 2020
by
João Alexandre Cunha
Committed by
Shinya Maeda
Oct 06, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds Terraform.latest.gitlab-ci.yml CI template
parent
5d8842ad
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
165 additions
and
10 deletions
+165
-10
changelogs/unreleased/feat-jcunha-adds-terraform-ci-latest-template.yml
...eleased/feat-jcunha-adds-terraform-ci-latest-template.yml
+6
-0
doc/development/cicd/templates.md
doc/development/cicd/templates.md
+10
-9
lib/gitlab/ci/templates/Terraform.latest.gitlab-ci.yml
lib/gitlab/ci/templates/Terraform.latest.gitlab-ci.yml
+22
-0
lib/gitlab/ci/templates/Terraform/Base.latest.gitlab-ci.yml
lib/gitlab/ci/templates/Terraform/Base.latest.gitlab-ci.yml
+53
-0
lib/gitlab/template/gitlab_ci_yml_template.rb
lib/gitlab/template/gitlab_ci_yml_template.rb
+1
-1
spec/lib/gitlab/ci/templates/Terraform/base_gitlab_ci_yaml_spec.rb
...gitlab/ci/templates/Terraform/base_gitlab_ci_yaml_spec.rb
+27
-0
spec/lib/gitlab/ci/templates/terraform_latest_gitlab_ci_yaml_spec.rb
...tlab/ci/templates/terraform_latest_gitlab_ci_yaml_spec.rb
+46
-0
No files found.
changelogs/unreleased/feat-jcunha-adds-terraform-ci-latest-template.yml
0 → 100644
View file @
925b7410
---
title
:
Adds a Terraform.latest.gitlab-ci.yml to support quick development of Terraform
related features
merge_request
:
43802
author
:
type
:
added
doc/development/cicd/templates.md
View file @
925b7410
...
@@ -13,15 +13,16 @@ This document explains how to develop [GitLab CI/CD templates](../../ci/examples
...
@@ -13,15 +13,16 @@ This document explains how to develop [GitLab CI/CD templates](../../ci/examples
All template files reside in the
`lib/gitlab/ci/templates`
directory, and are categorized by the following sub-directories:
All template files reside in the
`lib/gitlab/ci/templates`
directory, and are categorized by the following sub-directories:
| Sub-directory | Content |
[
Selectable in UI
](
#make-sure-the-new-template-can-be-selected-in-ui
)
|
| Sub-directory | Content |
[
Selectable in UI
](
#make-sure-the-new-template-can-be-selected-in-ui
)
|
|----------------|--------------------------------------------------------------|-----------------------------------------------------------------------|
|----------------|----------------------------------------------------|-----------------------------------------------------------------------|
|
`/AWS/*`
| Cloud Deployment (AWS) related jobs | No |
|
`/AWS/*`
| Cloud Deployment (AWS) related jobs | No |
|
`/Jobs/*`
| Auto DevOps related jobs | No |
|
`/Jobs/*`
| Auto DevOps related jobs | No |
|
`/Pages/*`
| Static site generators for GitLab Pages (for example Jekyll) | Yes |
|
`/Pages/*`
| Static site generators for GitLab Pages (for example Jekyll) | Yes |
|
`/Security/*`
| Security related jobs | Yes |
|
`/Security/*`
| Security related jobs | Yes |
|
`/Verify/*`
| Verify/testing related jobs | Yes |
|
`/Terraform/*`
| Infrastructure as Code related templates | No |
|
`/Workflows/*`
| Common uses of the
`workflow:`
keyword | No |
|
`/Verify/*`
| Verify/testing related jobs | Yes |
|
`/*`
(root) | General templates | Yes |
|
`/Workflows/*`
| Common uses of the
`workflow:`
keyword | No |
|
`/*`
(root) | General templates | Yes |
## Criteria
## Criteria
...
...
lib/gitlab/ci/templates/Terraform.latest.gitlab-ci.yml
0 → 100644
View file @
925b7410
include
:
-
template
:
Terraform/Base.latest.gitlab-ci.yml
# https://gitlab.com/gitlab-org/gitlab/blob/master/lib/gitlab/ci/templates/Terraform/Base.gitlab-ci.yml
stages
:
-
init
-
validate
-
build
-
deploy
init
:
extends
:
.init
validate
:
extends
:
.validate
build
:
extends
:
.build
deploy
:
extends
:
.deploy
dependencies
:
-
build
lib/gitlab/ci/templates/Terraform/Base.latest.gitlab-ci.yml
0 → 100644
View file @
925b7410
# Terraform/Base.latest
#
# The purpose of this template is to provide flexibility to the user so
# they are able to only include the jobs that they find interesting.
#
# Therefore, this template is not supposed to run any jobs. The idea is to only
# create hidden jobs. See: https://docs.gitlab.com/ee/ci/yaml/#hide-jobs
#
# There is a more opinionated template which we suggest the users to abide,
# which is the lib/gitlab/ci/templates/Terraform.latest.gitlab-ci.yml
image
:
name
:
registry.gitlab.com/gitlab-org/terraform-images/stable:latest
before_script
:
-
cd ${TF_ROOT}
variables
:
TF_ROOT
:
${CI_PROJECT_DIR}
cache
:
key
:
"
${TF_ROOT}"
paths
:
-
${TF_ROOT}/.terraform/
.init
:
&init
stage
:
init
script
:
-
gitlab-terraform init
.validate
:
&validate
stage
:
validate
script
:
-
gitlab-terraform validate
.build
:
&build
stage
:
build
script
:
-
gitlab-terraform plan
-
gitlab-terraform plan-json
artifacts
:
paths
:
-
${TF_ROOT}/plan.cache
reports
:
terraform
:
${TF_ROOT}/plan.json
.deploy
:
&deploy
stage
:
deploy
script
:
-
gitlab-terraform apply
when
:
manual
only
:
-
master
lib/gitlab/template/gitlab_ci_yml_template.rb
View file @
925b7410
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
module
Gitlab
module
Gitlab
module
Template
module
Template
class
GitlabCiYmlTemplate
<
BaseTemplate
class
GitlabCiYmlTemplate
<
BaseTemplate
BASE_EXCLUDED_PATTERNS
=
[
%r{
\.
latest
$
}
].
freeze
BASE_EXCLUDED_PATTERNS
=
[
%r{
\.
latest
\.
}
].
freeze
def
content
def
content
explanation
=
"# This file is a template, and might need editing before it works on your project."
explanation
=
"# This file is a template, and might need editing before it works on your project."
...
...
spec/lib/gitlab/ci/templates/Terraform/base_gitlab_ci_yaml_spec.rb
0 → 100644
View file @
925b7410
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
'Terraform/Base.latest.gitlab-ci.yml'
do
subject
(
:template
)
{
Gitlab
::
Template
::
GitlabCiYmlTemplate
.
find
(
'Terraform/Base.latest'
)
}
describe
'the created pipeline'
do
let
(
:user
)
{
create
(
:admin
)
}
let
(
:default_branch
)
{
'master'
}
let
(
:pipeline_branch
)
{
default_branch
}
let
(
:project
)
{
create
(
:project
,
:custom_repo
,
files:
{
'README.md'
=>
''
})
}
let
(
:service
)
{
Ci
::
CreatePipelineService
.
new
(
project
,
user
,
ref:
pipeline_branch
)
}
let
(
:pipeline
)
{
service
.
execute!
(
:push
)
}
let
(
:build_names
)
{
pipeline
.
builds
.
pluck
(
:name
)
}
before
do
stub_ci_pipeline_yaml_file
(
template
.
content
)
allow_any_instance_of
(
Ci
::
BuildScheduleWorker
).
to
receive
(
:perform
).
and_return
(
true
)
allow
(
project
).
to
receive
(
:default_branch
).
and_return
(
default_branch
)
end
it
'does not create any jobs'
do
expect
(
build_names
).
to
be_empty
end
end
end
spec/lib/gitlab/ci/templates/terraform_latest_gitlab_ci_yaml_spec.rb
0 → 100644
View file @
925b7410
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
'Terraform.latest.gitlab-ci.yml'
do
before
do
allow
(
Gitlab
::
Template
::
GitlabCiYmlTemplate
).
to
receive
(
:excluded_patterns
).
and_return
([])
end
subject
(
:template
)
{
Gitlab
::
Template
::
GitlabCiYmlTemplate
.
find
(
'Terraform.latest'
)
}
describe
'the created pipeline'
do
let_it_be
(
:user
)
{
create
(
:admin
)
}
let
(
:default_branch
)
{
'master'
}
let
(
:pipeline_branch
)
{
default_branch
}
let
(
:project
)
{
create
(
:project
,
:custom_repo
,
files:
{
'README.md'
=>
''
})
}
let
(
:service
)
{
Ci
::
CreatePipelineService
.
new
(
project
,
user
,
ref:
pipeline_branch
)
}
let
(
:pipeline
)
{
service
.
execute!
(
:push
)
}
let
(
:build_names
)
{
pipeline
.
builds
.
pluck
(
:name
)
}
before
do
stub_ci_pipeline_yaml_file
(
template
.
content
)
allow_any_instance_of
(
Ci
::
BuildScheduleWorker
).
to
receive
(
:perform
).
and_return
(
true
)
allow
(
project
).
to
receive
(
:default_branch
).
and_return
(
default_branch
)
end
context
'on master branch'
do
it
'creates init, validate and build jobs'
do
expect
(
build_names
).
to
include
(
'init'
,
'validate'
,
'build'
,
'deploy'
)
end
end
context
'outside the master branch'
do
let
(
:pipeline_branch
)
{
'patch-1'
}
before
do
project
.
repository
.
create_branch
(
pipeline_branch
)
end
it
'does not creates a deploy and a test job'
do
expect
(
build_names
).
not_to
include
(
'deploy'
)
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment