johnfo
johnfo

Reputation: 1842

How to get at results of Jenkins XRay Import Step XrayImportBuilder

When run the XrayImportBuilder step prints a lot of useful stuff to the Log but I can't see any simple way of getting at this information so it can be used from the Jenkinsfile script code. Specifically this appears in the Log:

XRAY_TEST_EXECS: ENT-8327

and I hoping to add this info to the current build description. Ideally the info would be returned from the call, but the result is empty. Alternatives might be to scan the log or I use a curl call and handle all the output - latter feels like a backwards step.

Upvotes: 1

Views: 339

Answers (1)

Cristiano Cunha
Cristiano Cunha

Reputation: 391

I was successful in extracting that information from the logs generated.

After the Xray import results stage I added:

stage('Extract Variable from log'){
  steps {
    script {
      def logContent = Jenkins.getInstance().getItemByFullName(env.JOB_NAME).getBuildByNumber(Integer.parseInt(env.BUILD_NUMBER)).logFile.text
      env.testExecs = (logContent =~ /XRAY_TEST_EXECS:.*/).findAll().first()
      echo testExecs
     }
  }
}
stage('Using variable from another stage') {
  steps {
    script {
      echo "${env.testExecs}"
    }
  }

You can change the REGEX used to your specific case. I've added the extracted value to a variable so that it can be used in another stages.

Upvotes: 1

Related Questions