Skip to content

Commit

Permalink
Final updates after 20241128
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasdille committed Dec 3, 2024
1 parent 0e19b42 commit 5bdb324
Show file tree
Hide file tree
Showing 56 changed files with 6,653 additions and 2,820 deletions.
600 changes: 0 additions & 600 deletions hands-on/2024-11-21/000_rollout/errored.tfstate

This file was deleted.

62 changes: 52 additions & 10 deletions hands-on/2024-11-21/000_rollout/exercise_gitlab/index.html

Large diffs are not rendered by default.

62 changes: 52 additions & 10 deletions hands-on/2024-11-21/000_rollout/exercise_ide/index.html

Large diffs are not rendered by default.

62 changes: 52 additions & 10 deletions hands-on/2024-11-21/000_rollout/exercise_project/index.html

Large diffs are not rendered by default.

62 changes: 52 additions & 10 deletions hands-on/2024-11-21/000_rollout/index.html

Large diffs are not rendered by default.

62 changes: 52 additions & 10 deletions hands-on/2024-11-21/010_jobs_and_stages/exercise/index.html

Large diffs are not rendered by default.

62 changes: 52 additions & 10 deletions hands-on/2024-11-21/020_variables/exercise/index.html

Large diffs are not rendered by default.

62 changes: 52 additions & 10 deletions hands-on/2024-11-21/030_script_blocks/exercise/index.html

Large diffs are not rendered by default.

62 changes: 52 additions & 10 deletions hands-on/2024-11-21/040_image/exercise/index.html

Large diffs are not rendered by default.

62 changes: 52 additions & 10 deletions hands-on/2024-11-21/050_defaults/exercise/index.html

Large diffs are not rendered by default.

62 changes: 52 additions & 10 deletions hands-on/2024-11-21/060_artifacts/exercise/index.html

Large diffs are not rendered by default.

62 changes: 52 additions & 10 deletions hands-on/2024-11-21/065_job_dependencies/exercise/index.html

Large diffs are not rendered by default.

64 changes: 53 additions & 11 deletions hands-on/2024-11-21/070_schedules/exercise/index.html

Large diffs are not rendered by default.

62 changes: 52 additions & 10 deletions hands-on/2024-11-21/090_unit_tests/exercise/index.html

Large diffs are not rendered by default.

62 changes: 52 additions & 10 deletions hands-on/2024-11-21/100_environments/exercise/index.html

Large diffs are not rendered by default.

63 changes: 53 additions & 10 deletions hands-on/2024-11-21/110_triggers/exercise/index.html

Large diffs are not rendered by default.

612 changes: 323 additions & 289 deletions hands-on/2024-11-21/120_templates/exercise/index.html

Large diffs are not rendered by default.

408 changes: 223 additions & 185 deletions hands-on/2024-11-21/130_rules/exercise/index.html

Large diffs are not rendered by default.

486 changes: 262 additions & 224 deletions hands-on/2024-11-21/140_merge_requests/exercise/index.html

Large diffs are not rendered by default.

474 changes: 256 additions & 218 deletions hands-on/2024-11-21/150_matrix_jobs/exercise/index.html

Large diffs are not rendered by default.

1,362 changes: 1,362 additions & 0 deletions hands-on/2024-11-21/200_permissions/exercises/index.html

Large diffs are not rendered by default.

484 changes: 261 additions & 223 deletions hands-on/2024-11-21/220_services/exercise/index.html

Large diffs are not rendered by default.

295 changes: 168 additions & 127 deletions hands-on/2024-11-21/230_docker/exercise/index.html

Large diffs are not rendered by default.

304 changes: 172 additions & 132 deletions hands-on/2024-11-21/240_registries/exercise/index.html

Large diffs are not rendered by default.

318 changes: 179 additions & 139 deletions hands-on/2024-11-21/250_releases/exercise/index.html

Large diffs are not rendered by default.

1,362 changes: 1,362 additions & 0 deletions hands-on/2024-11-21/252_branch_protection/exercises/index.html

Large diffs are not rendered by default.

62 changes: 52 additions & 10 deletions hands-on/2024-11-21/255_troubleshooting/exercise/index.html

Large diffs are not rendered by default.

62 changes: 52 additions & 10 deletions hands-on/2024-11-21/265_caches/exercise/index.html

Large diffs are not rendered by default.

344 changes: 192 additions & 152 deletions hands-on/2024-11-21/270_renovate/exercise/index.html

Large diffs are not rendered by default.

364 changes: 202 additions & 162 deletions hands-on/2024-11-21/280_security/exercise/index.html

Large diffs are not rendered by default.

65 changes: 53 additions & 12 deletions hands-on/2024-11-21/300_components/exercise/index.html

Large diffs are not rendered by default.

62 changes: 52 additions & 10 deletions hands-on/2024-11-21/310_steps/exercise/index.html

Large diffs are not rendered by default.

62 changes: 52 additions & 10 deletions hands-on/2024-11-21/320_secure_files/exercise/index.html

Large diffs are not rendered by default.

62 changes: 52 additions & 10 deletions hands-on/2024-11-21/404.html

Large diffs are not rendered by default.

This file was deleted.

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

62 changes: 52 additions & 10 deletions hands-on/2024-11-21/index.html

Large diffs are not rendered by default.

70 changes: 56 additions & 14 deletions hands-on/2024-11-21/navigation/index.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion hands-on/2024-11-21/search/search_index.json

Large diffs are not rendered by default.

Binary file modified hands-on/2024-11-21/sitemap.xml.gz
Binary file not shown.
64 changes: 53 additions & 11 deletions hands-on/2024-11-21/you_are_done/index.html

Large diffs are not rendered by default.

64 changes: 53 additions & 11 deletions hands-on/2024-11-21/you_are_ready/index.html

Large diffs are not rendered by default.

46 changes: 44 additions & 2 deletions slides/2024-11-21/160_gitlab_ci/010_jobs_and_stages/slides.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Pipelines are stored in `.gitlab-ci.yml`

## YAML (YAML Ain't Markup Language)

Human-readable data serialization format
Human-readable data serialization format [](https://yaml.org/)

1. Fields:

Expand Down Expand Up @@ -76,6 +76,40 @@ projects:
---
## YAML to JSON
```yaml
top:
- item1: value1
- item2:
subitem1: value2
subitem2: value3
- item3: value
subitem1: value4
```
```json
{
"top:" [
{ "item1": "value1" },
{ "item2": { "subitem1": "value2", "subitem2": "value3" } },
{ "item3": "value", "subitem1": "value4" }
]
}
```

---

## Tools for YAML/JSON

- JSON query `jq` [](https://github.com/jqlang/jq)
- JSON viewer `jless` [](https://jless.io)
- YAML query `yq` [](https://github.com/mikefarah/yq)
- Linter
- `yamllint` [](https://github.com/adrienverge/yamllint)
- Spectral by Stoplight [](https://stoplight.io/spectral)
---

## Jobs

Minimal job:
Expand Down Expand Up @@ -147,7 +181,7 @@ See chapter [Jobs and stages](/hands-on/2024-11-21/010_jobs_and_stages/exercise/

---

## Pro tip: Skip pipeline for push
## Pro tip 1: Skip pipeline for push

Sometimes a pipeline run is not desirable

Expand All @@ -170,3 +204,11 @@ Provide a push option:
```bash
git push -o ci.skip
```

---

## Pro tip 2: Pipeline Editor

The web UI offers a pipeline editor

Integrated syntax checking
169 changes: 88 additions & 81 deletions slides/2024-11-21/160_gitlab_ci/110_triggers/slides.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,24 @@ Launch pipeline in separate project [](https://docs.gitlab.com/ee/ci/pipelines/m

Use the `trigger` keyword [](https://docs.gitlab.com/ee/ci/yaml/index.html#trigger)

### Example
### Examples

Trigger a pipeline in another project:

```yaml
job_name:
trigger:
project: <path-to-project>
branch: main
```
`trigger.branch` is optional
Specify the branch to use:
```yaml
job_name:
trigger:
project: <path-to-project>
branch: main
```
---
Expand Down Expand Up @@ -124,32 +132,6 @@ See chapter [Triggers](/hands-on/2024-11-21/110_triggers/exercise/)

---

## Pro tip 1: Variable inheritence

Downstream pipelines inherit some variables [](https://docs.gitlab.com/ee/ci/pipelines/downstream_pipelines.html#pass-cicd-variables-to-a-downstream-pipeline)

Job variables are passed on unless:

```yaml
job_name:
inherit:
variables: false
```

Predefined variables must be redefined as job variables:

```yaml
job_name:
variables:
my_var: ${CI_COMMIT_REF_NAME}
trigger:
#...
```

Do not redefined masked variables - **they will not be masked**

---

## Pro tip 2: Wait for downstream pipeline

Upstream pipeline only waits for successful trigger
Expand All @@ -163,52 +145,11 @@ job_name:
strategy: depend
```

---

## Pro tip 3: Permissions for include

When including a file from another project...

```yaml
job_name:
trigger:
include:
- project: <path-to-project>
ref: main
file: <relative-path-to-file>
```

...the user must have the permission to run a pipeline in the other project
Useful when triggering the pipeline of a dependency

---

## Dynamic includes

Included file can also be generated before job start [](https://docs.gitlab.com/ee/ci/pipelines/downstream_pipelines.html#dynamic-child-pipelines)

```yaml
generate:
script:
- |
cat <<EOF >child.yaml
test:
script:
- printenv
EOF
artifacts:
paths:
- child.yaml
use:
trigger:
include:
- artifact: child.yaml
job: generate
```

---

## Pro tip 4: Artifacts from parent pipeline
## Pro tip 1: Artifacts from parent pipeline

<i class="fa-duotone fa-triangle-exclamation"></i> Requires Enterprise Edition Premium [](https://docs.gitlab.com/ee/ci/pipelines/downstream_pipelines.html?tab=Multi-project+pipeline#fetch-artifacts-from-an-upstream-pipeline)

Expand Down Expand Up @@ -243,9 +184,39 @@ test:
```
<!-- .element: style="float: right; font-size: 0.7em; width: 25em;" -->

This works for `dotenv` reports as well [](https://docs.gitlab.com/ee/ci/variables/#control-which-jobs-receive-dotenv-variables)

`needs:project` [](https://docs.gitlab.com/ee/ci/yaml/#needsproject) requires Premium subscription [](https://docs.gitlab.com/ee/ci/jobs/job_artifacts_troubleshooting.html#error-message-this-job-could-not-start-because-it-could-not-retrieve-the-needed-artifacts) <i class="fa-duotone fa-solid fa-face-sad-tear"></i>

---

## Pro tip 5: Do not pass global variables
## Pro tip 2: Variable inheritence

Downstream pipelines inherit some variables [](https://docs.gitlab.com/ee/ci/pipelines/downstream_pipelines.html#pass-cicd-variables-to-a-downstream-pipeline)

Job variables are passed on unless:

```yaml
job_name:
inherit:
variables: false
```

Predefined variables must be redefined as job variables:

```yaml
job_name:
variables:
my_var: ${CI_COMMIT_REF_NAME}
trigger:
#...
```

Do not redefined masked variables - **they will not be masked**

---

## Pro tip 3: Do not pass global variables

Only allow job variables to be passed to downstream pipelines:

Expand All @@ -265,18 +236,54 @@ trigger-job:

---

## Pro tip 6: Artifacts across projects
## Pro tip 4: Types of variables to forward

Fetch artifacts from another project using `needs:project` [](https://docs.gitlab.com/ee/ci/yaml/#needsproject) requires Premium subscription [](https://docs.gitlab.com/ee/ci/jobs/job_artifacts_troubleshooting.html#error-message-this-job-could-not-start-because-it-could-not-retrieve-the-needed-artifacts) :sad:
Use `trigger:forward` [](https://docs.gitlab.com/ee/ci/yaml/#triggerforward) to define which types of variables to forward to downstream pipelines

Use `needs:pipeline:job` [](https://docs.gitlab.com/ee/ci/yaml/index.html#needspipelinejob) for parent-child pipelines [](https://docs.gitlab.com/ee/ci/pipelines/downstream_pipelines.html#parent-child-pipelines)
- `yaml_variables` - variables defined in the trigger job
- `pipeline_variables` - variables passed to this pipeline [](https://docs.gitlab.com/ee/ci/variables/index.html#cicd-variable-precedence)

Mind access leven and permissions for the triggering user
This only works for the direct downstream pipeline

Also mind the project allowlist for job tokens
---

### dotenv
## Pro tip 5: Permissions for include

It only works in the same project [](https://docs.gitlab.com/ee/ci/variables/#control-which-jobs-receive-dotenv-variables)
When including a file from another project...

Keywords `dependencies` and `needs` are supported
```yaml
job_name:
trigger:
include:
- project: <path-to-project>
ref: main
file: <relative-path-to-file>
```

...the user must have the permission to run a pipeline in the other project

---

## Pro tip 6: Dynamic includes

Included file can also be generated before job start [](https://docs.gitlab.com/ee/ci/pipelines/downstream_pipelines.html#dynamic-child-pipelines)

```yaml
generate:
script:
- |
cat <<EOF >child.yaml
test:
script:
- printenv
EOF
artifacts:
paths:
- child.yaml
use:
trigger:
include:
- artifact: child.yaml
job: generate
```
29 changes: 28 additions & 1 deletion slides/2024-11-21/160_gitlab_ci/120_templates/slides.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ The following pipeline... result in the following job:
image: alpine
variables:
foo: bar
my_var: my_val
script: pwd
job_name:
extends: .template
variables:
bar: baz
my_var: also_my_val
```

<!-- .element: style="float: left; width: 25em;" -->
Expand All @@ -108,6 +110,7 @@ job_name:
variables:
foo: bar
bar: baz
my_var: also_my_val
script: pwd
```

Expand Down Expand Up @@ -174,7 +177,31 @@ job_name:

---

## Pro tip 3: Public Template Library
## Pro tip 3: Organizing templates in repositories

Once you are hooked on templates, you want to organize them in a repository

### Versioning

Use tags and releases to mark versions

### Single repository

Easy to find/browse, hard to version

Apply separate versioning: docker/v1.0.0, helm/v1.0.2, k8s/v1.2.0

### Repository per topic

Separation of concerns

Harder to find/browse, easier to version

Create versions separately

---

## Pro tip 4: Public Template Library

Project to help building professional pipelines [](https://to-be-continuous.gitlab.io/doc/)

Expand Down
Loading

0 comments on commit 5bdb324

Please sign in to comment.