To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/1180254799.141475.1554473189711%40mail.yahoo.com.
Hi monger_39
The job keep logs in 2 files: log and log-indexYou can read more in https://github.com/jenkinsci/jep/blob/master/jep/210/README.adoc#replace-aggregation-with-single-log-stream
But how to find this numbers?
1. You can write specific text to log (for example "Run
TESTENV=TestEnv_1_2_1" where every number is nested steps)
2. and then find this text from logs and calculate number
Here is example jenkinsfile for find correct URLs:
// Test data. Means, that you write unique key text in every log
instead
step=[64, 14, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
timestamps {
node('master') {
logIndex=getLogMap()
echo "${logIndex}"
for (int t = 0; t < 13 ; t++) {
int index_t=t, e = t+1
stepURL=getURL(logIndex, "TestEnv_${e}")
echo "TestEnv_${e} ${stepURL}"
b=''
if(e==1){b='_1'}
for (int tt = 0; tt < step[index_t]; tt++) {
e2 = tt+1
stepURL=getURL(logIndex, "TestEnv_${e}_${e2}${b}")
echo "TestEnv_${e}_${e2}${b} ${stepURL}"
} //for
} //for
}//node
}//timestamps
my shared library used in Jenkinsfile:
import jenkins.branch.NameMangler
import groovy.transform.Field
@Field def keyString = 'Run TESTENV=TestEnv'
def getLogMap() {
def tokens = "${env.JOB_NAME}".tokenize('/')
def repo = tokens[tokens.size()-2]
try {
def i
def result=[:]
exec = """
set +x
LOG_FILE="\$JENKINS_HOME/jobs/${repo}/branches/${NameMangler.apply(env.BRANCH_NAME)}/builds/\$BUILD_ID/log"
LOG_INDEX_FILE="\$JENKINS_HOME/jobs/${repo}/branches/${NameMangler.apply(env.BRANCH_NAME)}/builds/\$BUILD_ID/log-index"
LOG_LINES=\$(grep --byte-offset --text "${keyString}"
"\$LOG_FILE"| sed "s/[^[:print:]\t]//g;
s/\\(^[0-9]*:\\).*=\\(.*\\)/\\1 \\2/g; s/'\$//g" | awk -F" "
'!_[\$2]++')
LOG_INDEX=\$(grep '.* .*' "\$LOG_INDEX_FILE")
while read -r line ; do
offset=\$(echo \$line | cut -d ":" -f1)
str=\$(echo \$line | cut -d " " -f2)
if [[ "X\$offset" == "X" ]]; then
echo "Offset if empty in line=\$line"
continue
fi
index=\$(echo "\$LOG_INDEX" | awk '\$1 > '\$offset' {
print prev; exit; } { prev = \$2 }')
echo "\$str \$index"
done <<< "\$LOG_LINES"
"""
for(line in sh(script: exec, returnStdout:
true).trim().tokenize('\n')) {
i=line.tokenize()
result.put(i[0], i[1])
}
return result
} catch (error) {
throw (error)
}
}
def getURL(logIndex, findString) {
findString=findString.replaceAll(".*=", "")
return
"${env.BUILD_URL}execution/node/${logIndex."${findString}"}/log/"
}
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/196150282.123291.1554469062126%40mail.yahoo.com.
For more options, visit https://groups.google.com/d/optout.
-- WBD, Viacheslav Dubrovskyi
thx for the detailed answer!thx, M.
But wow, that is way more complex than I had anticipated !
Do you know if it is possible to get the ID at runtime for a given step ?
In my case the step that shows the workspace link is showing "Allocate node : Start"
which I assume would correspond to the 'node {...}' code right ?
We would actually want to insert a link to the workspace from the testcase itself;
that means that the testbench would need to find/get it from the system.
Easiest would then be to expose that from the DSL script; something like:
node ($my_node) {
env.ws_id = this.getMyID()
RunTheTests()
}
Any idea ?
Note that in my environment I do not seem to have a 'log-index' file which means that
your code would not work out of the box. I'be been looking through the generated <nr>.log
and <nr>.xml files to see if there is an easy correlation but no luck sofar.
I do see that in the
JENKINS_HOME/jobs/MY_JOB/builds/BUILD_NR/workflow/
there are a number of NR.xml files. And the one that I am looking for (50.xml) has:
* a <node class="cps.n.StepStartNode" >
* a section <s.a.WorkspaceActionImpl> which contains a non-empty <node>MY_NODE</node> section
which could point at another (simpler?) algorithm to find the proper ID
Hi monger_39,
Look to this issue https://issues.jenkins-ci.org/browse/JENKINS-28119
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/1362741409.1660247.1554983436293%40mail.yahoo.com.
For more options, visit https://groups.google.com/d/optout.
-- WBD, Viacheslav Dubrovskyi