Hi Viacheslavthx for the detailed answer!
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

thx, M.

    On Wednesday, April 10, 2019, 3:57:34 PM GMT+2, Viacheslav Dubrovskyi 
<dub...@gmail.com> wrote:  
 
  
Hi monger_39
 The job keep logs in 2 files: log and log-index 
You can read more 
inhttps://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/"
 }
 
 
 

 
 
 05.04.2019 15:57, 'monger_39' via Jenkins Users пишет:
  
 
 Dear Jenkins users, 
  sorry to contact you with this, but I am at a loss where to find or ask the 
following.
 
 I have a scripted parallel pipeline job. Within each of the stages test steps 
are run (under NUnit)
 that generate detailed logs per step, and a summary in the console. To make 
life easier for us we,
 when a test fail generates an assert, wish to insert a workspace link to that 
detailed file.
 With that it would be very easy to navigate to the details from the TestResult 
page.
 
 (with the previous matrix implementation this works fine)
 
 However, when running the pipeline, some 'strange' number is inserted in the 
workspace link,
 like the '50' and '57' in these links :
 
        
http://jenkins:8080/job/my_job_name/lastCompletedBuild/execution/node/50/ws/
        
http://jenkins:8080/job/my_job_name/lastCompletedBuild/execution/node/57/ws/
 
 obviously these are not the real build nr's. In this case that was 53.
  
  --> How can I, within my code, find those numbers ??
  
   I've been searching for hours on this, but can't find anything on it ... 
  thx, M.
    -- 
 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-users+unsubscr...@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 

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/597be5f7-1f2e-bbb4-be2f-57832b5cda8c%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
  

-- 
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-users+unsubscr...@googlegroups.com.
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.

Reply via email to