Skip to content

Commit b015f62

Browse files
committed
docs(examples): add example for needs.environment pipeline feature
The example can be used as test to ensure: - the environment is injected correctly to build and test parent pipelines - in case of existing environment variables the pipeline-level environment field wins over needs.environment. Signed-off-by: Massimiliano Giovagnoli <massimiliano.giovagnoli@chainguard.dev>
1 parent 9c1ffe7 commit b015f62

1 file changed

Lines changed: 87 additions & 0 deletions

File tree

examples/needs-environment.yaml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# SPDX-FileCopyrightText: 2022 Chainguard, Inc
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# This is a sample configuration file to demonstrate how to use the
5+
# pipeline needs.environment feature for build and test pipelines,
6+
# to inject transparently environment variables to the parent pipeline.
7+
#
8+
# For more information about melange's built-in golang support check out:
9+
# https://github.com/chainguard-dev/melange/blob/main/docs/BUILD-PROCESS.md
10+
#
11+
package:
12+
name: example
13+
version: 0.1.0
14+
epoch: 0
15+
16+
environment:
17+
contents:
18+
packages:
19+
- busybox
20+
- ca-certificates-bundle
21+
keyring:
22+
- https://packages.wolfi.dev/os/wolfi-signing.rsa.pub
23+
repositories:
24+
- https://packages.wolfi.dev/os
25+
26+
pipeline:
27+
- name: Expect an environment.
28+
environment:
29+
FOO: "foo"
30+
runs: |
31+
set -u
32+
echo "FOO: ${FOO}"
33+
if [[ "${FOO}" != "foo" ]]; then
34+
echo "Expected FOO=foo, got FOO=${FOO}"
35+
exit 1
36+
fi
37+
38+
- name: Expect an environment.
39+
runs: |
40+
set -u
41+
echo "BAZ: ${BAZ}"
42+
if [[ "${BAZ}" != "baz" ]]; then
43+
echo "Expected BAZ=baz, got BAZ=${FOO}"
44+
exit 1
45+
fi
46+
47+
- name: Inject an environment transparently to the parent pipeline.
48+
needs:
49+
environment:
50+
FOO: "bar"
51+
BAZ: "baz"
52+
53+
test:
54+
environment:
55+
contents:
56+
packages:
57+
- busybox
58+
keyring:
59+
- https://packages.wolfi.dev/os/wolfi-signing.rsa.pub
60+
- local-melange.rsa.pub
61+
repositories:
62+
- https://packages.wolfi.dev/os
63+
- packages
64+
pipeline:
65+
- name: Expect an environment.
66+
environment:
67+
FOO: "foo"
68+
runs: |
69+
set -u
70+
echo "FOO: ${FOO}"
71+
if [[ "${FOO}" != "foo" ]]; then
72+
echo "Expected FOO=foo, got FOO=${FOO}"
73+
exit 1
74+
fi
75+
- name: Expect an environment.
76+
runs: |
77+
set -u
78+
echo "BAZ: ${BAZ}"
79+
if [[ "${BAZ}" != "baz" ]]; then
80+
echo "Expected BAZ=baz, got BAZ=${FOO}"
81+
exit 1
82+
fi
83+
- name: Inject an environment transparently to the parent pipeline.
84+
needs:
85+
environment:
86+
FOO: "bar"
87+
BAZ: "baz"

0 commit comments

Comments
 (0)