github.com/argoproj/argo-cd/v2@v2.10.9/docs/operator-manual/notifications/services/webhook.md (about) 1 # Webhook 2 3 The webhook notification service allows sending a generic HTTP request using the templatized request body and URL. 4 Using Webhook you might trigger a Jenkins job, update GitHub commit status. 5 6 ## Parameters 7 8 The Webhook notification service configuration includes following settings: 9 10 - `url` - the url to send the webhook to 11 - `headers` - optional, the headers to pass along with the webhook 12 - `basicAuth` - optional, the basic authentication to pass along with the webhook 13 - `insecureSkipVerify` - optional bool, true or false 14 - `retryWaitMin` - Optional, the minimum wait time between retries. Default value: 1s. 15 - `retryWaitMax` - Optional, the maximum wait time between retries. Default value: 5s. 16 - `retryMax` - Optional, the maximum number of retries. Default value: 3. 17 18 ## Retry Behavior 19 20 The webhook service will automatically retry the request if it fails due to network errors or if the server returns a 5xx status code. The number of retries and the wait time between retries can be configured using the `retryMax`, `retryWaitMin`, and `retryWaitMax` parameters. 21 22 The wait time between retries is between `retryWaitMin` and `retryWaitMax`. If all retries fail, the `Send` method will return an error. 23 24 ## Configuration 25 26 Use the following steps to configure webhook: 27 28 1 Register webhook in `argocd-notifications-cm` ConfigMap: 29 30 ```yaml 31 apiVersion: v1 32 kind: ConfigMap 33 metadata: 34 name: <config-map-name> 35 data: 36 service.webhook.<webhook-name>: | 37 url: https://<hostname>/<optional-path> 38 headers: #optional headers 39 - name: <header-name> 40 value: <header-value> 41 basicAuth: #optional username password 42 username: <username> 43 password: <api-key> 44 insecureSkipVerify: true #optional bool 45 ``` 46 47 2 Define template that customizes webhook request method, path and body: 48 49 ```yaml 50 apiVersion: v1 51 kind: ConfigMap 52 metadata: 53 name: <config-map-name> 54 data: 55 template.github-commit-status: | 56 webhook: 57 <webhook-name>: 58 method: POST # one of: GET, POST, PUT, PATCH. Default value: GET 59 path: <optional-path-template> 60 body: | 61 <optional-body-template> 62 trigger.<trigger-name>: | 63 - when: app.status.operationState.phase in ['Succeeded'] 64 send: [github-commit-status] 65 ``` 66 67 3 Create subscription for webhook integration: 68 69 ```yaml 70 apiVersion: argoproj.io/v1alpha1 71 kind: Application 72 metadata: 73 annotations: 74 notifications.argoproj.io/subscribe.<trigger-name>.<webhook-name>: "" 75 ``` 76 77 ## Examples 78 79 ### Set GitHub commit status 80 81 ```yaml 82 apiVersion: v1 83 kind: ConfigMap 84 metadata: 85 name: <config-map-name> 86 data: 87 service.webhook.github: | 88 url: https://api.github.com 89 headers: #optional headers 90 - name: Authorization 91 value: token $github-token 92 ``` 93 94 2 Define template that customizes webhook request method, path and body: 95 96 ```yaml 97 apiVersion: v1 98 kind: ConfigMap 99 metadata: 100 name: <config-map-name> 101 data: 102 service.webhook.github: | 103 url: https://api.github.com 104 headers: #optional headers 105 - name: Authorization 106 value: token $github-token 107 108 template.github-commit-status: | 109 webhook: 110 github: 111 method: POST 112 path: /repos/{{call .repo.FullNameByRepoURL .app.spec.source.repoURL}}/statuses/{{.app.status.operationState.operation.sync.revision}} 113 body: | 114 { 115 {{if eq .app.status.operationState.phase "Running"}} "state": "pending"{{end}} 116 {{if eq .app.status.operationState.phase "Succeeded"}} "state": "success"{{end}} 117 {{if eq .app.status.operationState.phase "Error"}} "state": "error"{{end}} 118 {{if eq .app.status.operationState.phase "Failed"}} "state": "error"{{end}}, 119 "description": "ArgoCD", 120 "target_url": "{{.context.argocdUrl}}/applications/{{.app.metadata.name}}", 121 "context": "continuous-delivery/{{.app.metadata.name}}" 122 } 123 ``` 124 125 ### Start Jenkins Job 126 127 ```yaml 128 apiVersion: v1 129 kind: ConfigMap 130 metadata: 131 name: <config-map-name> 132 data: 133 service.webhook.jenkins: | 134 url: http://<jenkins-host>/job/<job-name>/build?token=<job-secret> 135 basicAuth: 136 username: <username> 137 password: <api-key> 138 139 type: Opaque 140 ``` 141 142 ### Send form-data 143 144 ```yaml 145 apiVersion: v1 146 kind: ConfigMap 147 metadata: 148 name: <config-map-name> 149 data: 150 service.webhook.form: | 151 url: https://form.example.com 152 headers: 153 - name: Content-Type 154 value: application/x-www-form-urlencoded 155 156 template.form-data: | 157 webhook: 158 form: 159 method: POST 160 body: key1=value1&key2=value2 161 ``` 162 163 ### Send Slack 164 165 ```yaml 166 apiVersion: v1 167 kind: ConfigMap 168 metadata: 169 name: <config-map-name> 170 data: 171 service.webhook.slack_webhook: | 172 url: https://hooks.slack.com/services/xxxxx 173 headers: 174 - name: Content-Type 175 value: application/json 176 177 template.send-slack: | 178 webhook: 179 slack_webhook: 180 method: POST 181 body: | 182 { 183 "attachments": [{ 184 "title": "{{.app.metadata.name}}", 185 "title_link": "{{.context.argocdUrl}}/applications/{{.app.metadata.name}}", 186 "color": "#18be52", 187 "fields": [{ 188 "title": "Sync Status", 189 "value": "{{.app.status.sync.status}}", 190 "short": true 191 }, { 192 "title": "Repository", 193 "value": "{{.app.spec.source.repoURL}}", 194 "short": true 195 }] 196 }] 197 } 198 ```