Reputation: 570
I am learning jenkins on my own and I do not have much experience. I just found out about warnings-ng plugin and I am trying to get acces to tokens in my pipeline:
pipeline {
agent any
stages {
stage('analysis') {
steps {
script{
bat'''
cppcheck "C:/Users/anton/Desktop/railway" --xml --xml-version=2 . 2> cppcheck.xml
'''
}
}
}
stage('Test'){
steps {
script {
def cppCheck = scanForIssues tool: cppCheck(pattern: 'cppcheck.xml')
publishIssues issues: [cppCheck]
echo "${ANALYSIS_ISSUES_COUNT}"
}
}
}
}
}
as mentioned in the warnings-ng documentation but I get an error No such property: ANALYSIS_ISSUES_COUNT for class: groovy.lang.Binding
how would be the right syntax to access the token? or is there anything needed to do before accessing to it, as far as I understood I just need the token macro plugin installed, which I have, and the warnings-ng plugin provided those tokens to be accessible, am I wrong?
Upvotes: 2
Views: 510
Reputation: 56
use tm step.
def newIssuesCountString = tm stringWithMacro: '${ANALYSIS_ISSUES_COUNT, type="NEW"}'
int newIssuesCount = newIssuesCountString as int
def totalIssuesCountString = tm stringWithMacro: '${ANALYSIS_ISSUES_COUNT, type="TOTAL"}'
int totalIssuesCount = totalIssuesCountString as int
reference1 : https://www.jenkins.io/doc/pipeline/steps/token-macro/
reference2 : https://github.com/jenkinsci/warnings-ng-plugin/blob/master/doc/Documentation.md#token-macro-support
Upvotes: 4