/
jenkins-action.ts
94 lines (82 loc) · 2.38 KB
/
jenkins-action.ts
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import codepipeline = require('@aws-cdk/aws-codepipeline');
import { Construct } from '@aws-cdk/core';
import { Action } from '../action';
import { IJenkinsProvider, jenkinsArtifactsBounds } from "./jenkins-provider";
/**
* The type of the Jenkins Action that determines its CodePipeline Category -
* Build, or Test.
* Note that a Jenkins provider, even if it has the same name,
* must be separately registered for each type.
*/
export enum JenkinsActionType {
/**
* The Action will have the Build Category.
*/
BUILD,
/**
* The Action will have the Test Category.
*/
TEST
}
/**
* Construction properties of {@link JenkinsAction}.
*/
export interface JenkinsActionProps extends codepipeline.CommonActionProps {
/**
* The source to use as input for this build.
*/
readonly inputs?: codepipeline.Artifact[];
/**
*
*/
readonly outputs?: codepipeline.Artifact[];
/**
* The Jenkins Provider for this Action.
*/
readonly jenkinsProvider: IJenkinsProvider;
/**
* The name of the project (sometimes also called job, or task)
* on your Jenkins installation that will be invoked by this Action.
*
* @example 'MyJob'
*/
readonly projectName: string;
/**
* The type of the Action - Build, or Test.
*/
readonly type: JenkinsActionType;
}
/**
* Jenkins build CodePipeline Action.
*
* @see https://docs.aws.amazon.com/codepipeline/latest/userguide/tutorials-four-stage-pipeline.html
*/
export class JenkinsAction extends Action {
private readonly props: JenkinsActionProps;
constructor(props: JenkinsActionProps) {
super({
...props,
category: props.type === JenkinsActionType.BUILD
? codepipeline.ActionCategory.BUILD
: codepipeline.ActionCategory.TEST,
provider: props.jenkinsProvider.providerName,
owner: 'Custom',
artifactBounds: jenkinsArtifactsBounds,
version: props.jenkinsProvider.version,
});
this.props = props;
}
protected bound(_scope: Construct, _stage: codepipeline.IStage, _options: codepipeline.ActionBindOptions):
codepipeline.ActionConfig {
if (this.actionProperties.category === codepipeline.ActionCategory.BUILD) {
this.props.jenkinsProvider._registerBuildProvider();
} else {
this.props.jenkinsProvider._registerTestProvider();
}
return {
configuration: {
ProjectName: this.props.projectName,
},
};
}
}