-
Notifications
You must be signed in to change notification settings - Fork 2
/
ontrackCliValidateWithTestResults.groovy
93 lines (79 loc) · 2.67 KB
/
ontrackCliValidateWithTestResults.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import net.nemerosa.ontrack.jenkins.pipeline.utils.ParamUtils
import net.nemerosa.ontrack.jenkins.pipeline.validate.Validation
import net.nemerosa.ontrack.jenkins.pipeline.graphql.GraphQL
def call(Map<String, ?> params = [:]) {
if (ontrackCliFailsafe()) return
// Not for pull requests
if (env.BRANCH_NAME ==~ 'PR-.*') {
echo "No Ontrack for pull requests."
return
}
boolean logging = ParamUtils.getLogging(params, env.ONTRACK_LOGGING)
// Parameters
boolean ignoreStatusIfResults = ParamUtils.getBooleanParam(params, 'ignoreStatusIfResults', true)
boolean useBuildDuration = ParamUtils.getBooleanParam(params, 'useBuildDuration', true)
// Getting results details
def results = params.results
int passed = results?.passCount ?: 0
int skipped = results?.skipCount ?: 0
int failed = results?.failCount ?: 0
// Status to use
if (results && ignoreStatusIfResults) {
params.status = null
}
// GraphQL query
String query = '''
mutation ValidateBuildWithTests(
$project: String!,
$branch: String!,
$build: String!,
$validation: String!,
$description: String!,
$runInfo: RunInfoInput,
$passed: Int!,
$skipped: Int!,
$failed: Int!,
$status: String,
) {
validateBuildWithTests(input: {
project: $project,
branch: $branch,
build: $build,
validation: $validation,
description: $description,
runInfo: $runInfo,
passed: $passed,
skipped: $skipped,
failed: $failed,
status: $status,
}) {
validationRun {
id
}
errors {
message
}
}
}
'''
// Validation parameters
Validation validation = new Validation("ontrack-cli-validate-tests")
Map<String,?> variables = validation.variables(this, params, false)
// Tests args
variables.passed = passed
variables.skipped = skipped
variables.failed = failed
// GraphQL call
def response = ontrackCliGraphQL(
logging: logging,
query: query,
variables: variables,
)
// Checks for errors
if (GraphQL.checkForMutationErrors(response, 'validateBuildWithTests', ontrackCliIgnoreErrors())) {
// Validation run properties
Validation.setValidationRunProperties(this, params, response, 'validateBuildWithTests')
}
// Returning the results
return results
}