Last active
March 16, 2020 15:05
-
-
Save bmpc/ae2c4ca8ec7d2713eb23f5df35bfd19d to your computer and use it in GitHub Desktop.
[Xray Cloud] Robot Framework Jenkins pipeline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pipeline { | |
environment { | |
client_id = "XXXXXXXX" | |
client_secret = "XXXXXXXXX" | |
} | |
agent { | |
dockerfile { | |
args '--entrypoint=\'\'' | |
} | |
} | |
stages { | |
stage("Run Tests") { | |
steps { | |
script { | |
echo "Executing Robot Tests..." | |
sh "pwd" | |
sh(script:"robot keyword_driven.robot", returnStatus:false) | |
} | |
} | |
} | |
stage("Upload Results") { | |
steps { | |
script { | |
echo "Authenticating with Xray REST API..." | |
def token = sh(returnStdout: true, script: "curl -H \"Content-Type: application/json\" -X POST --data '{ \"client_id\": \"$client_id\", \"client_secret\": \"$client_secret\" }' https://xray.cloud.xpand-it.com/api/v1/authenticate") | |
echo "Authentication Token: $token" | |
echo "Uploading Robot Report to Xray..." | |
def date = sh(returnStdout: true, script: "date").trim() | |
echo "Creating info file for Test Exec..." | |
def meta = readJSON text: "{ \ | |
\"fields\": { \ | |
\"project\": { \ | |
\"key\": \"STORE\" \ | |
}, \ | |
\"issuetype\": { \ | |
\"name\": \"Test Execution\" \ | |
}, \ | |
\"summary\": \"Robot test results ${date}\", \ | |
\"fixVersions\": [ \ | |
{ \ | |
\"name\": \"1.0\" \ | |
} \ | |
] \ | |
}, \ | |
\"xrayFields\": { \ | |
\"testPlanKey\": \"STORE-34\" \ | |
} \ | |
}" | |
writeJSON file: "info.json", json: meta | |
echo "Uploading results to Xray..." | |
sh "curl -H \"Content-Type: multipart/form-data\" -X POST -F results=@output.xml -F info=@info.json -H \"Authorization: Bearer $token\" https://xray.cloud.xpand-it.com/api/v1/import/execution/robot/multipart" | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment