-
Notifications
You must be signed in to change notification settings - Fork 2
/
ontrackCliBuildMetaInfo.groovy
71 lines (55 loc) · 1.86 KB
/
ontrackCliBuildMetaInfo.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
65
66
67
68
69
70
71
import net.nemerosa.ontrack.jenkins.pipeline.graphql.GraphQL
import net.nemerosa.ontrack.jenkins.pipeline.properties.MetaInfoPropertyUtils
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 build meta info for pull requests."
return
}
boolean logging = ParamUtils.getLogging(params, env.ONTRACK_LOGGING)
String project = ParamUtils.getParam(params, "project", env.ONTRACK_PROJECT_NAME as String)
String branch = ParamUtils.getParam(params, "branch", env.ONTRACK_BRANCH_NAME as String)
String build = ParamUtils.getParam(params, "build", env.ONTRACK_BUILD_NAME as String)
boolean append = ParamUtils.getBooleanParam(params, "append", true)
// GraphQL query
String query = '''
mutation BuildMetaInfo(
$project: String!,
$branch: String!,
$build: String!,
$metaInfoPropertyAppend: Boolean!,
$metaInfoPropertyItems: [MetaInfoPropertyItemInput!]!,
) {
setBuildMetaInfoProperty(input: {
project: $project,
branch: $branch,
build: $build,
append: $metaInfoPropertyAppend,
items: $metaInfoPropertyItems,
}) {
errors {
message
}
}
}
'''
// GraphQL variables
Map<String,?> variables = [
project: project,
branch: branch,
build: build,
metaInfoPropertyAppend: append,
]
// Meta info property
MetaInfoPropertyUtils.setVariables(params, variables)
// GraphQL call
def response = ontrackCliGraphQL(
logging: logging,
query: query,
variables: variables,
)
// Checks for errors
GraphQL.checkForMutationErrors(response, 'setBuildMetaInfoProperty', ontrackCliIgnoreErrors())
}