Skip to content

Commit

Permalink
add additional constants and attributes #28
Browse files Browse the repository at this point in the history
  • Loading branch information
tt-marcel committed Nov 22, 2023
1 parent e484a3e commit 1e313be
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
37 changes: 32 additions & 5 deletions vars/pipeline2ATX.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ def call(log = false, jobName = '', int buildNumber = 0) {

def filename = "${build.getParent().getDisplayName()}_${build.getNumber()}"
def attributes = getBuildAttributes(build)
def constants = getBuildConstants(build)
def executionSteps = getExecutionSteps(build, log)

if (log) {
logText = getConsoleLog(build)
logFile = "${filename}.log"
}
def json = generateJsonReport(build, attributes, executionSteps, logFile)
def json = generateJsonReport(build, attributes, constants, executionSteps, logFile)
// reset build because it's not serializable
build = null

Expand Down Expand Up @@ -93,9 +94,11 @@ def getRawBuild(String jobName, int buildNumber) {
*/
def getBuildAttributes(build) {
def attributes = []
def buildUrl = build.absoluteUrl
def buildId = build.id
def buildAttributes = [BUILD_URL: buildUrl, BUILD_ID: buildId]
def buildAttributes = [PRODUCT_VERSION: "${PRODUCT_VERSION}".toString(),
GIT_URL: "${GIT_URL}".toString(),
JENKINS_PIPELINE: build.getDisplayName(),
JENKINS_URL: build.getAbsoluteUrl(),
JENKINS_WORKSPACE: "${WORKSPACE}".toString()]
buildAttributes.putAll(params)
buildAttributes.each { k, v ->
if (v) {
Expand All @@ -105,6 +108,29 @@ def getBuildAttributes(build) {
return attributes
}

/**
* Collects all relevant build information and parameter as a map for constant.
*
* @param build
* the pipeline raw build
* @return the collected build information and parameters
*/
def getBuildConstants(build) {
def constants = []
def buildConstants = [PRODUCT_NAME: "${PRODUCT_NAME}".toString(),
GIT_COMMIT: "${GIT_COMMIT}".toString(),
JENKINS_BUILD_ID: build.id,
JENKINS_EXECUTOR_NUMBER: "${EXECUTOR_NUMBER}".toString(),
JENKINS_NODE_NAME: "${NODE_NAME}".toString()]
buildConstants.putAll(params)
buildConstants.each { k, v ->
if (v) {
constants.add([key: k, value: v.toString()])
}
}
return constants
}

/**
* Generates a TEST-GUIDE compatible JSON report of the pipeline build.
*
Expand All @@ -118,7 +144,7 @@ def getBuildAttributes(build) {
* the log file name if per-step logging is enabled
* @return the formatted JSON report
*/
def generateJsonReport(build, attributes, executionTestSteps, logFile) {
def generateJsonReport(build, attributes, constants, executionTestSteps, logFile) {
Map testcase = [:]

testcase.put("@type", "testcase")
Expand All @@ -131,6 +157,7 @@ def generateJsonReport(build, attributes, executionTestSteps, logFile) {
if (logFile) {
testcase.put("artifacts", [logFile])
}
testcase.put("constants", constants)
testcase.put("executionTestSteps", executionTestSteps)
def testCases = [testcase]

Expand Down
3 changes: 3 additions & 0 deletions vars/pipeline2ATX.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The report is compressed as a zip file within the build workspace and can be upl
<ul>
<li><a href="https://plugins.jenkins.io/pipeline-utility-steps/">Pipeline Utility Steps Plugin</a></li>
<li><a href="https://plugins.jenkins.io/pipeline-stage-view/">Pipeline Stage View Plugin</a></li>
<li>Environment variable "TEST_LEVEL" with a string of the corresponding test level</li>
<li>Environment variable "PRODUCT_NAME" with the name of the software product</li>
<li>Environment variable "PRODUCT_VERSION" with the version number of the software product</li>
</ul>
<p></p>
<dl>
Expand Down

0 comments on commit 1e313be

Please sign in to comment.