-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
55 lines (48 loc) · 2.65 KB
/
Jenkinsfile
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
pipeline {
agent any
environment {
// this is the API key you created before
AUTOMAGICALLY_TOKEN = credentials('AUTOMAGICALLY_TOKEN')
}
stages {
stage("Execute Automagically") {
steps {
script {
final String baseUrl = "https://app.octomind.dev"
final String url = "${baseUrl}/api/v2/execute"
final String header = "Content-Type: application/json"
def matchesOrgAndRepo = ("${env.GIT_URL}".replaceAll("/\$", "") =~ ".*(/|:)(.*)/([^.]*)(.git)?\$")
final String owner = matchesOrgAndRepo[0][2]
final String repo = matchesOrgAndRepo[0][3]
matchesOrgAndRepo = null
// publicly accessible url to your deployment
final String testTargetUrl = "https://storage.googleapis.com/mocktopus/index.html"
// your testTargetId that you also get from us
final String testTargetId = "35c8bfca-48d2-4eb2-8042-4ee50707a295"
final String data = """{
"url": "$testTargetUrl",
"testTargetId": "$testTargetId",
"context": {
"source": "github",
"repo": "$repo",
"owner": "$owner",
"sha": "${env.GIT_COMMIT}",
"ref": "${env.GIT_BRANCH}"
}
}"""
final def (String response, String code) = sh(script: "curl -s -w '\\n%{response_code}' $url --header '$header' --header 'x-api-key: $AUTOMAGICALLY_TOKEN' --data '$data'", returnStdout: true).trim().tokenize("\n")
if (code == '202') {
def matches = response =~/"id":"(.+?)"/
final String testReportId = matches[0][1]
final String testReportUrl = "${baseUrl}/testreports/${testReportId}"
currentBuild.description = """<a href="${testReportUrl}">Link to Test Report</a>"""
echo "You can view your Test Report here: ${testReportUrl}"
} else {
currentBuild.description = "Execution unsuccessful. Got status ${code}. Response: ${response}"
echo "Execution unsuccessful. Got status ${code}. Response: ${response}"
}
}
}
}
}
}