-
Notifications
You must be signed in to change notification settings - Fork 2
/
ontrackCliPromote.groovy
64 lines (54 loc) · 1.84 KB
/
ontrackCliPromote.groovy
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
import net.nemerosa.ontrack.jenkins.pipeline.graphql.GraphQL
import net.nemerosa.ontrack.jenkins.pipeline.utils.ParamUtils
def call(Map<String, ?> params = [:]) {
if (ontrackCliFailsafe()) return
// Not for pull requests
if (env.BRANCH_NAME ==~ 'PR-.*') {
echo "No Ontrack for pull requests."
return
}
String project = ParamUtils.getParam(params, "project", env.ONTRACK_PROJECT_NAME)
String branch = ParamUtils.getParam(params, "branch", env.ONTRACK_BRANCH_NAME)
String build = ParamUtils.getParam(params, "build", env.ONTRACK_BUILD_NAME)
String promotion = ParamUtils.getParam(params, "promotion")
String description = params.description ?: ""
boolean logging = ParamUtils.getLogging(params, env.ONTRACK_LOGGING)
// GraphQL query
String query = '''
mutation CreatePromotionRun(
$project: String!,
$branch: String!,
$build: String!,
$promotion: String!,
$description: String,
) {
createPromotionRun(input: {
project: $project,
branch: $branch,
build: $build,
promotion: $promotion,
description: $description,
}) {
errors {
message
}
}
}
'''
// Query variables
Map<String, ?> variables = [
project : project,
branch : branch,
build : build,
promotion : promotion,
description: description,
]
// GraphQL call
def response = ontrackCliGraphQL(
logging: logging,
query: query,
variables: variables,
)
// Checks for errors
GraphQL.checkForMutationErrors(response, 'createPromotionRun', ontrackCliIgnoreErrors())
}