From 1573c9059a4dd61edd850133445c9e82af0e05c1 Mon Sep 17 00:00:00 2001 From: vanisrikaniti Date: Fri, 15 Nov 2024 19:12:34 -0500 Subject: [PATCH 1/3] feat-pagerduty - added conversion for pagerduty plugin --- convert/jenkinsjson/convert.go | 7 ++ .../convertTestFiles/pagerduty/Jenkinsfile | 75 ++++++++++++++++++ .../convertTestFiles/pagerduty/pagerduty.yaml | 16 ++++ .../pagerduty/pagerduty_snippet.json | 30 ++++++++ .../pagerdutyChangeEvent/Jenkinsfile | 43 +++++++++++ .../pagerDutyChangeevent.yaml | 14 ++++ .../pagerDutyChangeevent_snippet.json | 31 ++++++++ convert/jenkinsjson/json/pager_duty.go | 76 +++++++++++++++++++ convert/jenkinsjson/json/pager_duty_test.go | 72 ++++++++++++++++++ samples/jenkins/Jenkinsfile | 66 +++++++++++++++- 10 files changed, 428 insertions(+), 2 deletions(-) create mode 100644 convert/jenkinsjson/convertTestFiles/pagerduty/Jenkinsfile create mode 100644 convert/jenkinsjson/convertTestFiles/pagerduty/pagerduty.yaml create mode 100644 convert/jenkinsjson/convertTestFiles/pagerduty/pagerduty_snippet.json create mode 100644 convert/jenkinsjson/convertTestFiles/pagerdutyChangeEvent/Jenkinsfile create mode 100644 convert/jenkinsjson/convertTestFiles/pagerdutyChangeEvent/pagerDutyChangeevent.yaml create mode 100644 convert/jenkinsjson/convertTestFiles/pagerdutyChangeEvent/pagerDutyChangeevent_snippet.json create mode 100644 convert/jenkinsjson/json/pager_duty.go create mode 100644 convert/jenkinsjson/json/pager_duty_test.go diff --git a/convert/jenkinsjson/convert.go b/convert/jenkinsjson/convert.go index 7e92b77..8db4def 100644 --- a/convert/jenkinsjson/convert.go +++ b/convert/jenkinsjson/convert.go @@ -694,9 +694,16 @@ func collectStepsWithID(currentNode jenkinsjson.Node, stepWithIDList *[]StepWith for _, step := range steps { *stepWithIDList = append(*stepWithIDList, StepWithID{Step: step, ID: id}) } + case "withKubeConfig": *stepWithIDList = append(*stepWithIDList, StepWithID{Step: jenkinsjson.ConvertKubeCtl(currentNode, currentNode.ParameterMap), ID: id}) + case "pagerdutyChangeEvent": + *stepWithIDList = append(*stepWithIDList, StepWithID{Step: jenkinsjson.ConvertPagerDutyChangeEvent(currentNode, currentNode.ParameterMap), ID: id}) + + case "pagerduty": + *stepWithIDList = append(*stepWithIDList, StepWithID{Step: jenkinsjson.ConvertPagerDuty(currentNode, currentNode.ParameterMap), ID: id}) + default: placeholderStr := fmt.Sprintf("echo %q", "This is a place holder for: "+currentNode.AttributesMap["jenkins.pipeline.step.type"]) b, err := json.MarshalIndent(currentNode.ParameterMap, "", " ") diff --git a/convert/jenkinsjson/convertTestFiles/pagerduty/Jenkinsfile b/convert/jenkinsjson/convertTestFiles/pagerduty/Jenkinsfile new file mode 100644 index 0000000..98cd97d --- /dev/null +++ b/convert/jenkinsjson/convertTestFiles/pagerduty/Jenkinsfile @@ -0,0 +1,75 @@ +pipeline { + agent any + environment { + // Ensure your PagerDuty routing key and integration key are securely stored in Jenkins credentials. + PAGERDUTY_ROUTING_KEY = "your_routing_key" + PAGERDUTY_DEDUP_KEY = "your_dedup_key" + PAGERDUTY_INTEGRATION_KEY = "your_integration_key" // Add your integration key for change events here + } + stages { + stage('Build') { + steps { + echo 'Building...' + // Insert your build steps here + } + } + stage('Test') { + steps { + echo 'Testing...' + // Insert your test steps here + } + } + stage('Deploy') { + steps { + echo 'Deploying...' + // Insert your deploy steps here + } + } + } + post { + success { + echo 'Job succeeded!' + pagerduty( + resolve: true, + routingKey: "${env.PAGERDUTY_ROUTING_KEY}", + dedupKey: "${env.PAGERDUTY_DEDUP_KEY}", + incidentSummary: "Build Succeeded for ${env.JOB_NAME}", + incidentSeverity: "info", + incidentSource: "${env.JOB_NAME}" + ) + } + failure { + echo 'Job failed!' + pagerduty( + resolve: false, + routingKey: "${env.PAGERDUTY_ROUTING_KEY}", + dedupKey: "${env.PAGERDUTY_DEDUP_KEY}", + incidentSummary: "Build Failed for ${env.JOB_NAME}", + incidentSeverity: "critical", + incidentSource: "${env.JOB_NAME}" + ) + } + aborted { + echo 'Job was aborted!' + pagerduty( + resolve: false, + routingKey: "${env.PAGERDUTY_ROUTING_KEY}", + dedupKey: "${env.PAGERDUTY_DEDUP_KEY}", + incidentSummary: "Build Aborted for ${env.JOB_NAME}", + incidentSeverity: "warning", + incidentSource: "${env.JOB_NAME}" + ) + } + unstable { + echo 'Job is unstable!' + pagerduty( + resolve: false, + routingKey: "${env.PAGERDUTY_ROUTING_KEY}", + dedupKey: "${env.PAGERDUTY_DEDUP_KEY}", + incidentSummary: "Build Unstable for ${env.JOB_NAME}", + incidentSeverity: "warning", + incidentSource: "${env.JOB_NAME}" + ) + } + } +} \ No newline at end of file diff --git a/convert/jenkinsjson/convertTestFiles/pagerduty/pagerduty.yaml b/convert/jenkinsjson/convertTestFiles/pagerduty/pagerduty.yaml new file mode 100644 index 0000000..bb6207f --- /dev/null +++ b/convert/jenkinsjson/convertTestFiles/pagerduty/pagerduty.yaml @@ -0,0 +1,16 @@ +- step: + identifier: pagerduty51d22b + name: Pagerduty + spec: + image: plugins/pagerduty + settings: + dedup_key: E54EC853A59A3815EF3632D5F854CF26 + incident_severity: critical + incident_source: test-pager-duty + incident_summary: Build Failed for test-pager-duty + job_status: failure + log_level: debug + resolve: 'false' + routing_key: a666ad1326f34605d06c0dbd4d87c1cb + timeout: '' + type: Plugin \ No newline at end of file diff --git a/convert/jenkinsjson/convertTestFiles/pagerduty/pagerduty_snippet.json b/convert/jenkinsjson/convertTestFiles/pagerduty/pagerduty_snippet.json new file mode 100644 index 0000000..b9a7b80 --- /dev/null +++ b/convert/jenkinsjson/convertTestFiles/pagerduty/pagerduty_snippet.json @@ -0,0 +1,30 @@ +{ + "spanId": "51d22b52c315ebd9", + "traceId": "6d2b4c2026d5c84a377d2dd97898ad1a", + "parent": "test-pager-duty", + "all-info": "span(name: pagerduty, spanId: 51d22b52c315ebd9, parentSpanId: d948447763f8ffaa, traceId: 6d2b4c2026d5c84a377d2dd97898ad1a, attr: ci.pipeline.run.user:SYSTEM;harness-attribute:{\r\n \"incidentSeverity\" : \"critical\",\r\n \"incidentSource\" : \"test-pager-duty\",\r\n \"resolve\" : false,\r\n \"dedupKey\" : \"E54EC853A59A3815EF3632D5F854CF26\",\r\n \"routingKey\" : \"a666ad1326f34605d06c0dbd4d87c1cb\",\r\n \"incidentSummary\" : \"Build Failed for test-pager-duty\"\r\n};harness-attribute-extra-pip: io.jenkins.plugins.opentelemetry.MigrateHarnessUrlChildAction@72cf357e:io.jenkins.plugins.opentelemetry.MigrateHarnessUrlChildAction@72cf357e;harness-attribute-extra-pip: org.jenkinsci.plugins.workflow.actions.TimingAction@57568f5:org.jenkinsci.plugins.workflow.actions.TimingAction@57568f5;harness-others:;jenkins.pipeline.step.id:26;jenkins.pipeline.step.name:PagerDuty trigger/resolve step;jenkins.pipeline.step.plugin.name:pagerduty;jenkins.pipeline.step.plugin.version:0.7.1;jenkins.pipeline.step.type:pagerduty;)", + "name": "test-pager-duty #22", + "attributesMap": { + "harness-attribute-extra-pip: io.jenkins.plugins.opentelemetry.MigrateHarnessUrlChildAction@72cf357e": "io.jenkins.plugins.opentelemetry.MigrateHarnessUrlChildAction@72cf357e", + "harness-others": "", + "jenkins.pipeline.step.name": "PagerDuty trigger/resolve step", + "ci.pipeline.run.user": "SYSTEM", + "jenkins.pipeline.step.id": "26", + "jenkins.pipeline.step.type": "pagerduty", + "harness-attribute-extra-pip: org.jenkinsci.plugins.workflow.actions.TimingAction@57568f5": "org.jenkinsci.plugins.workflow.actions.TimingAction@57568f5", + "harness-attribute": "{\r\n \"incidentSeverity\" : \"critical\",\r\n \"incidentSource\" : \"test-pager-duty\",\r\n \"resolve\" : false,\r\n \"dedupKey\" : \"E54EC853A59A3815EF3632D5F854CF26\",\r\n \"routingKey\" : \"a666ad1326f34605d06c0dbd4d87c1cb\",\r\n \"incidentSummary\" : \"Build Failed for test-pager-duty\"\r\n}", + "jenkins.pipeline.step.plugin.name": "pagerduty", + "jenkins.pipeline.step.plugin.version": "0.7.1" + }, + "type": "Run Phase Span", + "parentSpanId": "d948447763f8ffaa", + "parameterMap": { + "incidentSource": "test-pager-duty", + "resolve": false, + "dedupKey": "E54EC853A59A3815EF3632D5F854CF26", + "incidentSummary": "Build Failed for test-pager-duty", + "incidentSeverity": "critical", + "routingKey": "a666ad1326f34605d06c0dbd4d87c1cb" + }, + "spanName": "pagerduty" +} diff --git a/convert/jenkinsjson/convertTestFiles/pagerdutyChangeEvent/Jenkinsfile b/convert/jenkinsjson/convertTestFiles/pagerdutyChangeEvent/Jenkinsfile new file mode 100644 index 0000000..00db39f --- /dev/null +++ b/convert/jenkinsjson/convertTestFiles/pagerdutyChangeEvent/Jenkinsfile @@ -0,0 +1,43 @@ +pipeline { + agent any + environment { + // Ensure your PagerDuty routing key and integration key are securely stored in Jenkins credentials. + PAGERDUTY_ROUTING_KEY = "your_routing_key" + PAGERDUTY_DEDUP_KEY = "your_dedup_key" + PAGERDUTY_INTEGRATION_KEY = "your_integration_key" // Add your integration key for change events here + } + stages { + stage('Build') { + steps { + echo 'Building...' + // Insert your build steps here + } + } + stage('Test') { + steps { + echo 'Testing...' + // Insert your test steps here + } + } + stage('Deploy') { + steps { + echo 'Deploying...' + // Insert your deploy steps here + } + } + } + post { + always { + // Create a change event in PagerDuty after the job completes, regardless of outcome + pagerdutyChangeEvent( + integrationKey: "${env.PAGERDUTY_INTEGRATION_KEY}", + summaryText: "Job ${env.JOB_NAME} completed with status ${currentBuild.currentResult}", + customDetails: [ + buildNumber: "${env.BUILD_NUMBER}", + jobName: "${env.JOB_NAME}", + jobURL: "${env.BUILD_URL}" + ] + ) + } + } +} \ No newline at end of file diff --git a/convert/jenkinsjson/convertTestFiles/pagerdutyChangeEvent/pagerDutyChangeevent.yaml b/convert/jenkinsjson/convertTestFiles/pagerdutyChangeEvent/pagerDutyChangeevent.yaml new file mode 100644 index 0000000..237f55e --- /dev/null +++ b/convert/jenkinsjson/convertTestFiles/pagerdutyChangeEvent/pagerDutyChangeevent.yaml @@ -0,0 +1,14 @@ +- step: + identifier: pagerdutychangeevent499434 + name: Pagerduty_Change_Event + spec: + image: plugins/pagerduty + settings: + custom_details: '{"buildNumber":"22","jobName":"test-pager-duty","jobURL":"http://localhost:8080/job/test-pager-duty/22/"}' + incident_source: '' + incident_summary: Job test-pager-duty completed with status SUCCESS + log_level: debug + routing_key: a666ad1326f34605d06c0dbd4d87c1cb + create_change_event: "true" + timeout: '' + type: Plugin \ No newline at end of file diff --git a/convert/jenkinsjson/convertTestFiles/pagerdutyChangeEvent/pagerDutyChangeevent_snippet.json b/convert/jenkinsjson/convertTestFiles/pagerdutyChangeEvent/pagerDutyChangeevent_snippet.json new file mode 100644 index 0000000..6243c2d --- /dev/null +++ b/convert/jenkinsjson/convertTestFiles/pagerdutyChangeEvent/pagerDutyChangeevent_snippet.json @@ -0,0 +1,31 @@ +{ + "spanId": "499434b70188dc78", + "traceId": "6d2b4c2026d5c84a377d2dd97898ad1a", + "parent": "test-pager-duty", + "all-info": "span(name: pagerdutyChangeEvent, spanId: 499434b70188dc78, parentSpanId: d948447763f8ffaa, traceId: 6d2b4c2026d5c84a377d2dd97898ad1a, attr: ci.pipeline.run.user:SYSTEM;harness-attribute:{\r\n \"customDetails\" : {\r\n \"buildNumber\" : \"22\",\r\n \"jobName\" : \"test-pager-duty\",\r\n \"jobURL\" : \"http://localhost:8080/job/test-pager-duty/22/\"\r\n },\r\n \"summaryText\" : \"Job test-pager-duty completed with status SUCCESS\",\r\n \"integrationKey\" : \"a666ad1326f34605d06c0dbd4d87c1cb\"\r\n};harness-attribute-extra-pip: io.jenkins.plugins.opentelemetry.MigrateHarnessUrlChildAction@4a32f3a7:io.jenkins.plugins.opentelemetry.MigrateHarnessUrlChildAction@4a32f3a7;harness-attribute-extra-pip: org.jenkinsci.plugins.workflow.actions.TimingAction@a2cf09d:org.jenkinsci.plugins.workflow.actions.TimingAction@a2cf09d;harness-others:;jenkins.pipeline.step.id:24;jenkins.pipeline.step.name:PagerDuty Change Event step;jenkins.pipeline.step.plugin.name:pagerduty;jenkins.pipeline.step.plugin.version:0.7.1;jenkins.pipeline.step.type:pagerdutyChangeEvent;)", + "name": "test-pager-duty #22", + "attributesMap": { + "harness-attribute-extra-pip: io.jenkins.plugins.opentelemetry.MigrateHarnessUrlChildAction@4a32f3a7": "io.jenkins.plugins.opentelemetry.MigrateHarnessUrlChildAction@4a32f3a7", + "harness-attribute-extra-pip: org.jenkinsci.plugins.workflow.actions.TimingAction@a2cf09d": "org.jenkinsci.plugins.workflow.actions.TimingAction@a2cf09d", + "harness-others": "", + "jenkins.pipeline.step.name": "PagerDuty Change Event step", + "ci.pipeline.run.user": "SYSTEM", + "jenkins.pipeline.step.id": "24", + "jenkins.pipeline.step.type": "pagerdutyChangeEvent", + "harness-attribute": "{\r\n \"customDetails\" : {\r\n \"buildNumber\" : \"22\",\r\n \"jobName\" : \"test-pager-duty\",\r\n \"jobURL\" : \"http://localhost:8080/job/test-pager-duty/22/\"\r\n },\r\n \"summaryText\" : \"Job test-pager-duty completed with status SUCCESS\",\r\n \"integrationKey\" : \"a666ad1326f34605d06c0dbd4d87c1cb\"\r\n}", + "jenkins.pipeline.step.plugin.name": "pagerduty", + "jenkins.pipeline.step.plugin.version": "0.7.1" + }, + "type": "Run Phase Span", + "parentSpanId": "d948447763f8ffaa", + "parameterMap": { + "summaryText": "Job test-pager-duty completed with status SUCCESS", + "customDetails": { + "jobName": "test-pager-duty", + "jobURL": "http://localhost:8080/job/test-pager-duty/22/", + "buildNumber": "22" + }, + "integrationKey": "a666ad1326f34605d06c0dbd4d87c1cb" + }, + "spanName": "pagerdutyChangeEvent" +} diff --git a/convert/jenkinsjson/json/pager_duty.go b/convert/jenkinsjson/json/pager_duty.go new file mode 100644 index 0000000..901ea27 --- /dev/null +++ b/convert/jenkinsjson/json/pager_duty.go @@ -0,0 +1,76 @@ +package json + +import ( + "encoding/json" + "log" + + harness "github.com/drone/spec/dist/go" +) + +// ConvertNunit creates a Harness step for nunit plugin. +func ConvertPagerDuty(node Node, arguments map[string]interface{}) *harness.Step { + incidentSource, _ := arguments["incidentSource"].(string) + resolve, _ := arguments["resolve"].(bool) + dedupKey, _ := arguments["dedupKey"].(string) + incidentSummary, _ := arguments["incidentSummary"].(string) + incidentSeverity, _ := arguments["incidentSeverity"].(string) + routingKey, _ := arguments["routingKey"].(string) + + convertPagerduty := &harness.Step{ + Id: SanitizeForId(node.SpanName, node.SpanId), + Name: "Pagerduty", + Type: "plugin", + Spec: &harness.StepPlugin{ + Image: "plugins/pagerduty", + With: map[string]interface{}{ + "log_level": "debug", + "routing_key": routingKey, + "incident_summary": incidentSummary, + "incident_source": incidentSource, + "incident_severity": incidentSeverity, + "resolve": resolve, + "job_status": "failure", + "dedup_key": dedupKey, + }, + }, + } + + return convertPagerduty +} + +// ConvertNunit creates a Harness step for nunit plugin. +func ConvertPagerDutyChangeEvent(node Node, arguments map[string]interface{}) *harness.Step { + incidentSource, _ := arguments["incidentSource"].(string) + incidentSummary, _ := arguments["summaryText"].(string) + routingKey, _ := arguments["integrationKey"].(string) + customDetails, _ := arguments["customDetails"].(map[string]interface{}) + + customDetailsStr := "" + if customDetails != nil { + jsonBytes, err := json.Marshal(customDetails) + if err != nil { + log.Printf("Failed to marshal customDetails: %v", err) + } else { + customDetailsStr = string(jsonBytes) + } + } + + convertPagerdutyChangeEvent := &harness.Step{ + Name: "Pagerduty_Change_Event", + Type: "plugin", + Id: SanitizeForId(node.SpanName, node.SpanId), + Spec: &harness.StepPlugin{ + Image: "plugins/pagerduty", + With: map[string]interface{}{ + "log_level": "debug", + "routing_key": routingKey, + "incident_summary": incidentSummary, + "incident_source": incidentSource, + "create_change_event": true, + "custom_details": customDetailsStr, + }, + }, + } + + return convertPagerdutyChangeEvent +} diff --git a/convert/jenkinsjson/json/pager_duty_test.go b/convert/jenkinsjson/json/pager_duty_test.go new file mode 100644 index 0000000..7ce66c9 --- /dev/null +++ b/convert/jenkinsjson/json/pager_duty_test.go @@ -0,0 +1,72 @@ +package json + +import ( + "testing" + + harness "github.com/drone/spec/dist/go" + "github.com/google/go-cmp/cmp" +) + +func TestConvertPagerDuty(t *testing.T) { + + var tests []runner + tests = append(tests, prepare(t, "/pagerduty/pagerduty_snippet", &harness.Step{ + Id: "pagerduty51d22b", + Name: "Pagerduty", + Type: "plugin", + Spec: &harness.StepPlugin{ + Image: "plugins/pagerduty", + With: map[string]interface{}{ + "log_level": string("debug"), + "routing_key": string("a666ad1326f34605d06c0dbd4d87c1cb"), + "incident_summary": string("Build Failed for test-pager-duty"), + "incident_source": string("test-pager-duty"), + "incident_severity": string("critical"), + "resolve": bool(false), + "job_status": string("failure"), + "dedup_key": string("E54EC853A59A3815EF3632D5F854CF26"), + }, + }, + })) + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := ConvertPagerDuty(tt.input, tt.input.ParameterMap) + + if diff := cmp.Diff(got, tt.want); diff != "" { + t.Errorf("ConvertNunit() mismatch (-want +got):\n%s", diff) + } + }) + } +} + +func TestConvertPagerDutyChangeEvent(t *testing.T) { + + var tests []runner + tests = append(tests, prepare(t, "/pagerdutyChangeEvent/pagerdutyChangeEvent_snippet", &harness.Step{ + Id: "pagerdutyChangeEvent499434", + Name: "Pagerduty_Change_Event", + Type: "plugin", + Spec: &harness.StepPlugin{ + Image: "plugins/pagerduty", + With: map[string]interface{}{ + "log_level": string("debug"), + "routing_key": string("a666ad1326f34605d06c0dbd4d87c1cb"), + "incident_summary": string("Job test-pager-duty completed with status SUCCESS"), + "incident_source": string(""), + "custom_details": string(`{"buildNumber":"22","jobName":"test-pager-duty","jobURL":"http://localhost:8080/job/test-pager-duty/22/"}`), + "create_change_event": bool(true), + }, + }, + })) + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := ConvertPagerDutyChangeEvent(tt.input, tt.input.ParameterMap) + + if diff := cmp.Diff(got, tt.want); diff != "" { + t.Errorf("ConvertNunit() mismatch (-want +got):\n%s", diff) + } + }) + } +} diff --git a/samples/jenkins/Jenkinsfile b/samples/jenkins/Jenkinsfile index 137875f..cd0279f 100644 --- a/samples/jenkins/Jenkinsfile +++ b/samples/jenkins/Jenkinsfile @@ -575,8 +575,8 @@ line3''' stage('Run NUnit') { steps { script { - def xmlFileUrl = 'https://raw.githubusercontent.com/harness-community/test-jenkins-to-harness/refs/heads/main/nunit-test-result.xml' - def outputFilePath = 'TestResult.xml' + xmlFileUrl = 'https://raw.githubusercontent.com/harness-community/test-jenkins-to-harness/refs/heads/main/nunit-test-result.xml' + outputFilePath = 'TestResult.xml' bat """ powershell -Command "Invoke-WebRequest -Uri '${xmlFileUrl}' -OutFile '${outputFilePath}'" @@ -658,5 +658,67 @@ line3''' username: 'jenkins-test-user' } } + //Pagerduty plugin + post { + success { + echo 'Job succeeded!' + pagerduty( + resolve: true, + routingKey: "${env.PAGERDUTY_ROUTING_KEY}", + dedupKey: "${env.PAGERDUTY_DEDUP_KEY}", + incidentSummary: "Build Succeeded for ${env.JOB_NAME}", + incidentSeverity: "info", + incidentSource: "${env.JOB_NAME}" + ) + } + failure { + echo 'Job failed!' + pagerduty( + resolve: false, + routingKey: "${env.PAGERDUTY_ROUTING_KEY}", + dedupKey: "${env.PAGERDUTY_DEDUP_KEY}", + incidentSummary: "Build Failed for ${env.JOB_NAME}", + incidentSeverity: "critical", + incidentSource: "${env.JOB_NAME}" + ) + } + aborted { + echo 'Job was aborted!' + pagerduty( + resolve: false, + routingKey: "${env.PAGERDUTY_ROUTING_KEY}", + dedupKey: "${env.PAGERDUTY_DEDUP_KEY}", + incidentSummary: "Build Aborted for ${env.JOB_NAME}", + incidentSeverity: "warning", + incidentSource: "${env.JOB_NAME}" + ) + } + unstable { + echo 'Job is unstable!' + pagerduty( + resolve: false, + routingKey: "${env.PAGERDUTY_ROUTING_KEY}", + dedupKey: "${env.PAGERDUTY_DEDUP_KEY}", + incidentSummary: "Build Unstable for ${env.JOB_NAME}", + incidentSeverity: "warning", + incidentSource: "${env.JOB_NAME}" + ) + } + } + //pagerduty plugin change event + post { + always { + // Create a change event in PagerDuty after the job completes, regardless of outcome + pagerdutyChangeEvent( + integrationKey: "${env.PAGERDUTY_INTEGRATION_KEY}", + summaryText: "Job ${env.JOB_NAME} completed with status ${currentBuild.currentResult}", + customDetails: [ + buildNumber: "${env.BUILD_NUMBER}", + jobName: "${env.JOB_NAME}", + jobURL: "${env.BUILD_URL}" + ] + ) + } + } } } \ No newline at end of file From ce4229802a384ff01e24341fc353a033741de70f Mon Sep 17 00:00:00 2001 From: vanisrikaniti Date: Sat, 16 Nov 2024 12:54:12 -0500 Subject: [PATCH 2/3] typo --- convert/jenkinsjson/json/pager_duty.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/convert/jenkinsjson/json/pager_duty.go b/convert/jenkinsjson/json/pager_duty.go index 901ea27..7ee0a21 100644 --- a/convert/jenkinsjson/json/pager_duty.go +++ b/convert/jenkinsjson/json/pager_duty.go @@ -7,7 +7,7 @@ import ( harness "github.com/drone/spec/dist/go" ) -// ConvertNunit creates a Harness step for nunit plugin. +// ConvertPagerduty creates a Harness step for nunit plugin. func ConvertPagerDuty(node Node, arguments map[string]interface{}) *harness.Step { incidentSource, _ := arguments["incidentSource"].(string) resolve, _ := arguments["resolve"].(bool) @@ -38,7 +38,7 @@ func ConvertPagerDuty(node Node, arguments map[string]interface{}) *harness.Step return convertPagerduty } -// ConvertNunit creates a Harness step for nunit plugin. +// ConvertPagerduty creates a Harness step for nunit plugin. func ConvertPagerDutyChangeEvent(node Node, arguments map[string]interface{}) *harness.Step { incidentSource, _ := arguments["incidentSource"].(string) incidentSummary, _ := arguments["summaryText"].(string) From 6b2859a8f7a963c91dbb1ce8230d8d03274d522f Mon Sep 17 00:00:00 2001 From: vanisrikaniti Date: Sat, 16 Nov 2024 13:19:46 -0500 Subject: [PATCH 3/3] typo --- convert/jenkinsjson/json/pager_duty_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/convert/jenkinsjson/json/pager_duty_test.go b/convert/jenkinsjson/json/pager_duty_test.go index 7ce66c9..38d716e 100644 --- a/convert/jenkinsjson/json/pager_duty_test.go +++ b/convert/jenkinsjson/json/pager_duty_test.go @@ -34,7 +34,7 @@ func TestConvertPagerDuty(t *testing.T) { got := ConvertPagerDuty(tt.input, tt.input.ParameterMap) if diff := cmp.Diff(got, tt.want); diff != "" { - t.Errorf("ConvertNunit() mismatch (-want +got):\n%s", diff) + t.Errorf("ConvertPagerDuty() mismatch (-want +got):\n%s", diff) } }) } @@ -65,7 +65,7 @@ func TestConvertPagerDutyChangeEvent(t *testing.T) { got := ConvertPagerDutyChangeEvent(tt.input, tt.input.ParameterMap) if diff := cmp.Diff(got, tt.want); diff != "" { - t.Errorf("ConvertNunit() mismatch (-want +got):\n%s", diff) + t.Errorf("ConvertPagerDutyChangeEvent() mismatch (-want +got):\n%s", diff) } }) }