Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * A Jenkins pipeline demonstrating how layered product QE teams can perform their OCP
- * layered product testing when integrating into the Interop QE CI system using their
- * triggering service offering.
- */
- import java.time.Instant
- /**
- * Get xUnit urls for the given build. Requires the use of the NonCPS
- * annotation as getArtifacts method uses Jenkins API.
- * @return xUnit urls for the build
- */
- @NonCPS
- def getXunitUrls() {
- List xunitUrls = []
- List artifacts = currentBuild.rawBuild.getArtifacts()
- for (String artifact in artifacts) {
- if (artifact.getFileName().endsWith('.xml')) {
- xunitUrls.add(env.BUILD_URL + "artifact/${artifact}")
- }
- }
- return xunitUrls
- }
- node("master") {
- // declare variables
- String messageTopic = "product-scenario.test.complete"
- def ocp_info
- def message
- def product_info
- Boolean allowEmpty = false
- String testStatus
- def testRuntime
- timestamps{
- stage("parse message"){
- try{
- sh "printenv"
- // get ci message and write to disk
- message = readJSON text: params.get("CI_MESSAGE")
- writeJSON file: "ci-message.json", json: message
- // gather OpenShift details
- for (item in message['artifact']['products']) {
- if (item['name'].toLowerCase() == 'openshift') {
- ocp_info = item
- } else {
- product_info = item
- }
- }
- println("Testing OCP build: ${ocp_info['nvr']}")
- } catch (e){
- allowEmpty = true
- println("${e.toString()}")
- throw e
- } finally {
- archiveArtifacts artifacts: "*.json", fingerprint: false, allowEmptyArchive: allowEmpty
- }
- }
- stage("setup test environment"){
- println("Setting up test environment...")
- }
- stage("Run Tests"){
- dir("repo"){
- println("Running Tests")
- // save start time
- startTime = new Date().getTime()
- // clone mock_openshift repo to get sample xunit results
- git url: "https://github.com/openshift/jenkins.git", branch: "master"
- sh '''
- oc login https://api.daily-4.12-092201.dev.openshiftappsvc.org:6443 -u kubeadmin -p 9NJXn-WQEUD-XkYdY-zuWdL --insecure-skip-tls-verify
- export KUBECONFIG=~/.kube/config
- ./scripts/test-jenkins-template-install.sh
- '''
- // archive the xunit results from running the tests
- archiveArtifacts artifacts: "out/smoke/*.xml", fingerprint: false
- // save stop time
- stopTime = new Date().getTime()
- }
- // calculate test total runtime
- testRuntime = ((stopTime - startTime) / 1000).toInteger()
- //analyze the results, and set the test status
- testStatus = "passed"
- println("Finished test execution")
- }
- stage("build ci message") {
- println("Building product-scenario.test.complete ci message..")
- // build list of xunit urls
- List xunitUrls = getXunitUrls()
- // override default message topic (development usage)
- if (message['contact']['email'] != "pit-qe@redhat.com") {
- messageTopic += ".${message['contact']['email'].toString().split('@')[0]}"
- }
- // build message
- message['contact']['name'] = product_info['name']
- message['contact']['team'] = product_info['name']
- message['contact']['email'] = "jitsingh@redhat.com"
- message['contact']['url'] = env.JENKINS_URL
- message['run'] = [:]
- message['run']['url'] = env.BUILD_URL
- message['run']['log'] = env.BUILD_URL + "console"
- message['test'] = [:]
- message['test']['category'] = "interoperability"
- message['test']['namespace'] = "interop"
- message['test']['type'] = "layered-product"
- message['test']['result'] = testStatus
- message['test']['runtime'] = testRuntime
- message['test']['xunit_urls'] = xunitUrls
- message['generated_at'] = Instant.now().toString()
- println("${message}")
- println("CI message product-scenario.test.complete finished building!")
- // archive product-scenario.test.complete message
- archiveArtifacts artifacts: "*.json", fingerprint: false
- }
- stage("send ci message") {
- println("Sending product-scenario.test.complete ci message..")
- // set topic
- String topic = String.join(".", "VirtualTopic.qe.ci", "${messageTopic}")
- //MESSAGE_PROVIDER = Red Hat UMB or Red Hat UMB (stage) -> if accessible
- sendCIMessage providerName: params.MESSAGE_PROVIDER,
- overrides: [topic: topic],
- messageType: "Custom",
- messageContent: message.toString()
- println("CI message product-scenario.test.complete finished sending!")
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement