-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcodepipeline-helper.js
45 lines (42 loc) · 1.34 KB
/
codepipeline-helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'use strict'
const AWS = require('aws-sdk')
AWS.config.update({ region: process.env.REGION })
const codepipeline = new AWS.CodePipeline(process.env.REGION)
const PIPELINE_HISTORY = 'https://###REGION###.console.aws.amazon.com/codepipeline/home?region=###REGION####/view/###PIPELINE###/history'
module.exports.getPipelineExecutionDetails = (executionId, pipeline) => {
const promises = []
promises.push(getPipelineExecution(executionId, pipeline))
promises.push(getPipelineState(pipeline))
return Promise.all(promises).then(([execution, state]) => {
return {
execution: execution,
state: state,
executionHistoryUrl: PIPELINE_HISTORY
.replace(new RegExp('###REGION###', 'g'), process.env.REGION)
.replace(new RegExp('###PIPELINE###', 'g'), pipeline)
}
})
}
function getPipelineExecution (executionId, pipeline) {
const params = {
pipelineExecutionId: executionId,
pipelineName: pipeline
}
return new Promise((resolve, reject) => {
codepipeline.getPipelineExecution(params, (err, data) => {
if (err) reject(err)
else resolve(data)
})
})
}
function getPipelineState (pipeline) {
const params = {
name: pipeline
}
return new Promise((resolve, reject) => {
codepipeline.getPipelineState(params, (err, data) => {
if (err) reject(err)
else resolve(data)
})
})
}