Hi monger_39

The job keep logs in 2 files: log and log-index

You 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/"
}



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 [email protected] <mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/196150282.123291.1554469062126%40mail.yahoo.com <https://groups.google.com/d/msgid/jenkinsci-users/196150282.123291.1554469062126%40mail.yahoo.com?utm_medium=email&utm_source=footer>.
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 [email protected].
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.

Attachment: smime.p7s
Description: Криптографическая подпись S/MIME

Reply via email to