Skip to content

Commit 5e3d336

Browse files
authored
Add section to reference shared config in YAML (codefresh-io#715)
* Add section to reference shared config in YAML Added section to reference shared config and made content edits * Add reference shared config example to api Moved referencing shared config context as example to pipeline API and added xref in shared config topic * Update shared-configuration.md Added reference example to programmatic section with xrefs to CLI context command and full pipeline specifications * Minor content edits * Update shared-configuration.md * Update shared-configuration.md Fixed link * Update shared-configuration.md
1 parent 09bc4c4 commit 5e3d336

File tree

2 files changed

+79
-13
lines changed

2 files changed

+79
-13
lines changed

_docs/integrations/codefresh-api.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,35 @@ max-width="70%"
232232
Notice that you must prefix the name of the pipeline with your username and repository so that it becomes
233233
visible in the GUI under the correct project.
234234

235+
## Example: Referencing shared configuration contexts
236+
Use shared configuration contexts in your pipelines by referencing it in the pipeline's YAML. This method is an alternative to importing the shared configuration contexts with the variables to use from the UI.
237+
238+
Add the `spec.contexts` field followed by the name or names of the shared configuration context or contexts to use.
239+
240+
>**IMPORTANT**:
241+
Referencing shared configuration contexts with `spec.contexts` only works programmatically via the CLI/API.
242+
The UI-based YAML options (**inline YAML**, **Use YAML from Repository/URL**) do not support this.
243+
244+
245+
If you have a shared configuration named `test-hello` that includes the variable `test=hello`, you can add `spec.contexts.test-hello` to the pipeline YAML, and then reference this variable in the pipeline as you would any other variable.
246+
247+
{% highlight shell %}
248+
{% raw %}
249+
version: "1.0"
250+
kind: pipeline
251+
metadata:
252+
name: default/test-shared-config-from-pipe-spec
253+
spec:
254+
contexts:
255+
- test-hello
256+
steps:
257+
test:
258+
image: alpine
259+
commands:
260+
- echo ${{test}} # should output "hello"
261+
{% endraw %}
262+
{% endhighlight %}
263+
235264
## Full pipeline specification
236265

237266
If you don't want to create a pipeline from an existing one, you can also create your own YAML from scratch.

_docs/pipelines/configuration/shared-configuration.md

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,31 @@ You can share:
2020
* Any kind of YAML data (advanced)
2121

2222

23-
## Creating shared configuration
2423

25-
From the left sidebar click *Account settings* to enter your global settings. Then choose *Shared Configuration* from the left menu.
24+
## Creating shared configuration contexts
25+
26+
Create one or more shared configuration contexts at the account-level to use in pipelines.
27+
28+
1. In the Codefresh UI, on the toolbar, click the **Settings** icon.
29+
1. From the sidebar, select [**Shared Configuration**](https://g.codefresh.io/account-admin/account-conf/shared-config){:target="\_blank"}.
30+
1. Click **Add Configuration Context** and select the type of shared configuration context to add.
31+
1. Enter a name for the shared configuration context and click **Save**.
32+
1. Add one or more variables in Key = Value format.
33+
1. To allow access to all users, toggle **Allow access to all users** ON.
34+
1. Click **Save**.
35+
2636

2737
{% include
2838
image.html
2939
lightbox="true"
3040
file="/images/pipeline/shared-configuration/shared-configuration.png"
3141
url="/images/pipeline/shared-configuration/shared-configuration.png"
32-
alt="Creating shared configuration snippets"
33-
caption="Creating shared configuration snippets"
42+
alt="Creating shared configuration contexts"
43+
caption="Creating shared configuration contexts"
3444
max-width="50%"
3545
%}
3646

37-
You can create four types of shared configuration:
47+
You can create four types of shared configuration contexts:
3848

3949
* **Shared Configuration**: for environment variables
4050
* **Shared Secret**: for encrypted environment variables of sensitive data (access tokens, etc.)
@@ -82,6 +92,7 @@ max-width="60%"
8292
We recommend that you disable access for all values of type *shared secret* and *secret YAML* unless your organization has different needs.
8393

8494

95+
8596
## Using shared environment variables
8697

8798
Each pipeline has a set of environment variables that can be defined in the *Workflow* screen.
@@ -113,12 +124,13 @@ Once you click *Add* the values from the shared configuration will be appended t
113124
you have in your pipelines. In case of similar values the shared configuration will follow the [precedence rules]({{site.baseurl}}/docs/pipelines/variables/#user-provided-variables).
114125

115126

127+
116128
## Using shared Helm values
117129

118-
To use a shared YAML snippet for Helm values you can install a new Helm chart either from:
130+
To use a shared YAML snippet for Helm values you can install a new Helm chart either from the:
119131

120-
* The [Helm chart list]({{site.baseurl}}/docs/deployments/helm/helm-charts-and-repositories/)
121-
* The [Helm environment board]({{site.baseurl}}/docs/new-helm/helm-environment-promotion/#moving-releases-between-environments).
132+
* [Helm chart list]({{site.baseurl}}/docs/deployments/helm/helm-charts-and-repositories/)
133+
* [Helm environment board]({{site.baseurl}}/docs/deployments/helm/helm-environment-promotion/)
122134

123135
In both cases, when you see the Helm installation dialog you can import any of your YAML snippets
124136
to override the default chart values.
@@ -199,7 +211,7 @@ The shared variables can now be used across your pipelines.
199211

200212
## Sharing any kind of YAML data in pipelines
201213

202-
All the snippets from shared configuration are also available as context in the [Codefresh CLI](https://codefresh-io.github.io/cli/contexts/)
214+
All the snippets from shared configuration are also available as context in the [Codefresh CLI](https://codefresh-io.github.io/cli/contexts/).
203215

204216
This means that you can manipulate them programmatically and read their values in the pipeline in any way you see fit.
205217

@@ -223,15 +235,15 @@ spec:
223235

224236
### Example - custom value manipulation
225237

226-
Let's say that you have a YAML segment with the following contents:
238+
Let's say that you have a YAML segment with the following content:
227239

228240
{% highlight yaml %}
229241
favorite:
230242
drink: coffee
231243
food: pizza
232244
{% endhighlight %}
233245

234-
Here is a pipeline step that is reading the yaml snippet and extracts a value
246+
Here is a pipeline step that reads the YAML snippet and extracts a value:
235247

236248
`YAML`
237249
{% highlight yaml %}
@@ -254,9 +266,34 @@ I love eating pizza
254266

255267
## Manipulating shared configuration programmatically
256268

257-
You can also create/update/delete shared configuration via the [Codefresh CLI](https://codefresh-io.github.io/cli/) or [API]({{site.baseurl}}/docs/integrations/codefresh-api/).
269+
You can also manipulate shared configurations programmatically via the [Codefresh CLI](https://codefresh-io.github.io/cli/){:target="\_blank"} and the [Codefresh API](https://g.codefresh.io/api/){:target="\_blank"}.
270+
271+
For example, you can reference one or more shared configuration contexts directly in the YAML using `spec.contexts` as described below.
272+
273+
If you have a shared configuration named `test-hello` that includes the variable `test=hello`, you can add `spec.contexts.test-hello` to the pipeline YAML, and then reference this variable in the pipeline as you would any other variable.
274+
275+
{% highlight shell %}
276+
{% raw %}
277+
version: "1.0"
278+
kind: pipeline
279+
metadata:
280+
name: default/test-shared-config-from-pipe-spec
281+
spec:
282+
contexts:
283+
- test-hello
284+
steps:
285+
test:
286+
image: alpine
287+
commands:
288+
- echo ${{test}} # should output "hello"
289+
{% endraw %}
290+
{% endhighlight %}
291+
292+
293+
294+
For detailed information on how to create/update/delete shared configuration contexts via the CLI, see [Contexts](https://codefresh-io.github.io/cli/contexts/){:target="\_blank"}.
258295

259-
See the [context section](https://codefresh-io.github.io/cli/contexts/create-context/) in the CLI documentation.
296+
For information on all the options available in the _full Codefresh YAML_, see [Full pipeline specifications]({{site.baseurl}}/docs/integrations/codefresh-api/#full-pipeline-specification).
260297

261298

262299

0 commit comments

Comments
 (0)