Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit27b4fb9

Browse files
committed
Add promotion context example
Added example template to define promotion context and use in promotion hook
1 parentd6660b0 commit27b4fb9

File tree

2 files changed

+84
-54
lines changed

2 files changed

+84
-54
lines changed

‎_docs/promotions/promotion-context-promotion-workflows.md‎

Lines changed: 77 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ toc: true
1010

1111
##Promotion contexts in promotion hooks
1212

13-
Promotion Workflows with hooks in Codefresh GitOps have access to a standard set of[default parameters]({{site.baseurl}}/docs/promotions/promotion-hooks/#default-arguments-in-promotion-hooks), such as the release ID, product, and commit SHA. When you define these parameters in the hook as input parameters, their values are dynamically retrieved from the ongoing promotion.
13+
Promotion Workflows with hooks in Codefresh GitOps have access to a standard set of[default parameters]({{site.baseurl}}/docs/promotions/promotion-hooks/#default-arguments-in-promotion-hooks), such as the release ID,current release version,product, and commit SHA. When you define these parameters in the hook as input parameters, their values are dynamically retrieved from the ongoing promotion.
1414

1515
Because promotion hooks run within GitOps Runtimes in your own clusters, custom parameters such as Jira ticket IDs, approver names, or Slack channel names are not automatically exposed to the promotion process. To use these custom parameters in hooks, you have two options:
1616
* Define the custom parameters and their values manually in the workflow
@@ -104,29 +104,75 @@ max-width="60%"
104104
##Walkthough: Using promotion hooks in Promotion Flows to handle promotion failures
105105

106106
Promotion hooks are designed to take action or provide information related to a release and its environments when a promotion is triggered.
107-
In this walkthrough, you'll see how tousepromotion hooks to handle promotion failures, ensuring that stakeholders are notified with the right information—without needing to monitor the release manually.
107+
In this walkthrough, you'll see how tocreate and export apromotioncontext, and create promotionhooks and use the promotion context to handle promotion failures, ensuring that stakeholders are notified with the right information—without needing to monitor the release manually.
108108

109109
This walkthrough covers:
110+
*[Creating a Promotion Workflow template with a generic promotion context](#create-promotion-workflow-template-with-generic-promotion-context)
110111
*[Creating Promotion Workflows with hooks](#create-promotion-workflows-with-hooks)
111112
*[Assigning hooks in Promotion Flow](#assign-hooks-to-promotion-flow)
112113
*[Triggering hooks in Promotion Flow](#result-of-triggering-hooks-1-and-2-work-in-the-promotion-flow)
113114

115+
###Create Promotion Workflow template with generic promotion context
116+
117+
This Promotion Workflow template:
118+
* Defines a generic promotion context as a key-value map in JSON format.
119+
* Uses a single parameter,`context-params`, which is a JSON string of arbitrary keys and values, such as metadata for the promotion, Jira ticket references, base URLs.
120+
* Exports the promotion context as`PROMOTION_CONTEXT`, ensuring that it's available to any promotion hook which references it.
121+
122+
#####Example YAML
123+
124+
```yaml
125+
apiVersion:argoproj.io/v1alpha1
126+
kind:WorkflowTemplate
127+
metadata:
128+
name:set-promotion-context
129+
annotations:
130+
version:0.0.1
131+
codefresh.io/workflow-origin:promotion
132+
spec:
133+
entrypoint:generate-context
134+
templates:
135+
-name:generate-context
136+
serviceAccountName:hook
137+
inputs:
138+
parameters:
139+
-name:context-params
140+
description:JSON string of key-value pairs
141+
# Example: '{"JIRA_ISSUE_SOURCE_FIELD": "ABC-123", "JIRA_BASE_URL": "https://jira.example.com"}'
142+
script:
143+
image:alpine
144+
command:[sh]
145+
source:|
146+
echo '{{inputs.parameters.context-params}}' > /tmp/context.json
147+
CONTEXT_JSON=$(cat /tmp/context.json)
148+
149+
# Output the context as is
150+
echo "$CONTEXT_JSON" > /tmp/promotion-context.txt
151+
outputs:
152+
parameters:
153+
-name:PROMOTION_CONTEXT
154+
globalName:PROMOTION_CONTEXT
155+
valueFrom:
156+
path:/tmp/promotion-context.txt
157+
```
158+
114159
115160
### Create Promotion Workflows with hooks
116161
117-
####Hook 1: Create Jira ticket on promotion failure and export Jira
162+
#### Hook 1: Create Jira ticket on promotion failure and export Jiraissue URL through promotion context
118163
This hook performs two main actions:
119164
* Creates a Jira issue when a promotion fails.
120-
*Defines and exports a promotion context that stores the URL of the created Jira issue, making it available to later hooks in the same Promotion Flow.
165+
*References the exports a promotion context that stores the URL of the created Jira issue, making it available to later hooks in the same Promotion Flow.
121166
122167
123168
{: .table .table-bordered .table-hover}
124-
| Hook 1 feature| Description|
125-
| --------------| --------------|
126-
|**Two-step DAG structure**| The hook uses a Directed Acyclic Graph (DAG) with two tasks: first`create-issue`, then`set-promotion-context`. The second task depends on the successful creation of the Jira issue.|
127-
|**Jira issue creation**| The`create-issue` task uses a custom container to create a Jira ticket.|
128-
|**Promotion context definition**| After creating the Jira issue, the`set-promotion-context` task creates a JSON object with the full Jira issue URL. This JSON is saved to`/tmp/promotion-context.txt` and exported as the`PROMOTION_CONTEXT` global output.|
129-
|**Sharing information across hooks**| By exporting`PROMOTION_CONTEXT`, later hooks in the same Promotion Flow, have access to the Jira issue URL.|
169+
| Hook 1 feature | Description |
170+
|-----------------------------|---------------------------------------------------------------------------------------------------|
171+
| **Two-step DAG structure** | The hook defines a Directed Acyclic Graph (DAG) with two steps:`create-issue` followed by `set-promotion-context`, which depends on successful Jira issue creation. |
172+
| **Jira issue creation** | The `create-issue` step runs a container that creates a Jira issue and outputs its key or ID. |
173+
| **Referenced template** | The `set-promotion-context` step uses a reusable WorkflowTemplate named `set-promotion-context`, referencing its `generate-context` template. |
174+
| **Promotion context setup** | The `set-promotion-context` step passes a `context-params` JSON object with a dynamic Jira field value (`JIRA_ISSUE_SOURCE_FIELD`) from `create-issue` and a static base URL (`JIRA_ISSUE_URL`). It outputs this object as `PROMOTION_CONTEXT`. |
175+
| **Global sharing of context** | The exported `PROMOTION_CONTEXT` is globally accessible to any subsequent hook in the Promotion Flow. |
130176

131177

132178

@@ -151,14 +197,18 @@ spec:
151197
- name: create-issue
152198
template: create-issue
153199
- name: set-promotion-context
154-
template:set-promotion-context
200+
templateRef:
201+
name: set-promotion-context
202+
template: generate-context
155203
depends: "create-issue.Succeeded"
156204
arguments:
157205
parameters:
158-
-name:JIRA_ISSUE_SOURCE_FIELD
159-
value:"{{tasks.create-issue.outputs.parameters.JIRA_ISSUE_SOURCE_FIELD}}"
160-
-name:JIRA_ISSUE_URL
161-
value:https://testjira273.atlassian.net
206+
- name: context-params
207+
value: |
208+
{
209+
"JIRA_ISSUE_SOURCE_FIELD": "{{tasks.create-issue.outputs.parameters.JIRA_ISSUE_SOURCE_FIELD}}",
210+
"JIRA_ISSUE_URL": "https://testjira273.atlassian.net"
211+
}
162212
163213
- name: create-issue
164214
serviceAccountName: hook
@@ -208,54 +258,32 @@ spec:
208258
- /jira/jira_issue_manager.py
209259
env:
210260
- name: JIRA_BASE_URL
211-
value:'{{ inputs.parameters.JIRA_BASE_URL }}'
261+
value: ''
212262
- name: JIRA_USERNAME
213-
value:'{{ inputs.parameters.JIRA_USERNAME }}'
214-
-name:JIRA_API_KEY???
215-
value:'{{ inputs.parameters.JIRA_API_KEY }}'
263+
value: ''
264+
- name:JIRA_API_SECRET_KEY
265+
value: ''
216266
- name: ACTION
217267
value: 'issue_create'
218268
- name: ISSUE_PROJECT
219-
value:'{{ inputs.parameters.ISSUE_PROJECT }}'
269+
value: ''
220270
- name: ISSUE_SUMMARY
221-
value:'{{ inputs.parameters.ISSUE_SUMMARY }}'
271+
value: ''
222272
- name: ISSUE_DESCRIPTION
223-
value:'{{ inputs.parameters.ISSUE_DESCRIPTION }}'
273+
value: ''
224274
- name: ISSUE_COMPONENTS
225-
value:'{{ inputs.parameters.ISSUE_COMPONENTS }}'
275+
value: ''
226276
- name: ISSUE_CUSTOMFIELDS
227-
value:'{{ inputs.parameters.ISSUE_CUSTOMFIELDS }}'
277+
value: ''
228278
- name: ISSUE_TYPE
229-
value:'{{ inputs.parameters.ISSUE_TYPE }}'
279+
value: ''
230280
volumeMounts:
231281
- name: promotion-context
232282
mountPath: /tmp
233283
volumes:
234284
- name: promotion-context
235285
emptyDir: {}
236-
237-
-name:set-promotion-context
238-
serviceAccountName:hook
239-
inputs:
240-
parameters:
241-
-name:JIRA_ISSUE_SOURCE_FIELD
242-
-name:JIRA_ISSUE_URL
243-
script:
244-
image:alpine
245-
command:
246-
-sh
247-
source:|
248-
export JIRA_ISSUE_BASE_URL="{{inputs.parameters.JIRA_ISSUE_URL}}"
249-
export JIRA_ISSUE_SOURCE_FIELD="{{inputs.parameters.JIRA_ISSUE_SOURCE_FIELD}}"
250-
PROMOTION_CONTEXT=$(echo "{\"JIRA_ISSUE_URL\": \"${JIRA_ISSUE_URL}/browse/${JIRA_ISSUE_SOURCE_FIELD}\"}")
251-
echo "$PROMOTION_CONTEXT" > /tmp/promotion-context.txt
252-
253-
outputs:
254-
parameters:
255-
-name:PROMOTION_CONTEXT
256-
globalName:PROMOTION_CONTEXT
257-
valueFrom:
258-
path:/tmp/promotion-context.txt
286+
259287
```
260288
<br><br>
261289

@@ -267,7 +295,7 @@ This hook sends a Slack notification when a promotion fails. It uses the promoti
267295
| Hook 2 feature | Description |
268296
| -------------- | -------------- |
269297
| **Single-step notification flow** | This hook uses a simple, single `send-message` template to post a Slack message. |
270-
| **Detailed Slack notification** | The Slack message includes product name, commit SHA, promotion flow name, release URL, release ID, failed environments, error message, and **the Jira ticket URL**. |
298+
| **Detailed Slack notification** | The Slack messagetheincludes product name, commit SHA, promotion flow name, release URL, release ID, failed environments, error message, and **the Jira ticket URL**. |
271299
| **Dynamic inputs** | Parameters like `PRODUCT_NAME`, `COMMIT_SHA`, `ERROR_MESSAGE`, and `JIRA_ISSUE_URL` are passed dynamically, allowing the message to include real-time promotion failure details. |
272300
| **Simple and reusable Slack template** | The hook uses a standard Slack webhook and a flexible `SLACK_TEXT` format, making it easy to modify for different products or flows without changing the container logic. |
273301
| **Promotion context usage** | The `JIRA_ISSUE_URL` from the promotion context created in the previous hook is injected into the Slack message, linking the notification directly to the Jira ticket for tracking. |

‎_docs/promotions/promotion-hooks.md‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ Unlike Pre- and Post-Action Promotion Workflows, which operate on each applicati
2828
#####When are promotion hooks triggered?
2929
Promotion hooks can run at different stages of a product release:
3030
***Release**: When Promotion Flow trigger creates a product release:
31-
***On release start**: When a release is initiated
32-
***On release end**: When a release completes, whether**successful** or**failed**
31+
***On start**: When the release is initiated
32+
***On success**: When the release completes successfully
33+
***On failure**: When the release fails
3334
***Per environment**: When a release transitions through specific environments:
3435
***On start**: When the promotion reaches an environment
3536
***On success**: When the promotion completes successfully in an environment
@@ -50,7 +51,7 @@ See [Assigning promotion hooks in Promotion Flows](#assigning-promotion-hooks-in
5051
Explore examples in[Codefresh Hub for Argo](https://codefresh.io/argohub/){:target="\_blank"}.
5152

5253
#####Arguments in promotion hooks
53-
A default set of arguments are available to all Promotion Workflows withhooksd. See[Default arguments in Promotion Workflows with hooks](#default-arguments-for-promotion-hooks).
54+
A default set of arguments are available to all Promotion Workflows withhooks. See[Default arguments in Promotion Workflows with hooks](#default-arguments-for-promotion-hooks).
5455

5556
##Promotion hooks vs. Pre- and Post-Action Promotion Workflows
5657

@@ -79,8 +80,9 @@ The table below describes the default arguments that are replaced with values th
7980
{: .table .table-bordered .table-hover}
8081
| Parameter| Description| Notes|
8182
| --------------| --------------| --------------|
82-
|`RELEASE_URL`| The URL link to the release associated with the promotion.| All hooks|
83-
|`PRODUCT_NAME`| The name of the product for which the promotion release is running.| All hooks|
83+
|`RELEASE_URL`| The URL link to the release associated with the promotion.| All hooks|
84+
|`PRODUCT_NAME`| The name of the product for which the promotion release is running.| All hooks|
85+
|`VERSION`| The version of the current release.| All hooks|
8486
|`COMMIT_SHA`| The unique identifier (SHA) of the commit, generated by Git, that triggered the promotion and created the release.| All hooks|
8587
|`PROMOTION_FLOW_NAME`| The name of the Promotion Flow triggered for the release.| All hooks|
8688
|`RELEASE_ID`| The unique identifier of the release.| All hooks|

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp