how to derive HTTP link to workspace of a scripted parallel pipeline

35 views
Skip to first unread message

monger_39

unread,
Apr 5, 2019, 8:58:03 AM4/5/19
to jenkins...@googlegroups.com
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.

Lukas Resch

unread,
Apr 5, 2019, 9:18:14 AM4/5/19
to jenkins...@googlegroups.com
Hi,

Am 05.04.2019 um 14:57 schrieb 'monger_39' via Jenkins Users:
> 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.

Why are you not just publishing the test results on Jenkins? Thereby you
would get access to all test details via the web interface rather than
on the console.

I haven't used NUnit, but the JUnit plugin provides excatly what you
describe.

HTH

monger_39

unread,
Apr 5, 2019, 10:06:43 AM4/5/19
to jenkins...@googlegroups.com
we actually do publish the results (using xUnit). But specifically for any failed test, we
want to easily access the detailed (and quite large) log files to analyze what went wrong.
We could also publish all those log files as artifacts, but there are a lot of them.
As such, our current idea is still to find those files within the workspace.

--
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+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/bc3f55bc-c265-2d3e-2346-00446002ec60%40ngworx.ag.

For more options, visit https://groups.google.com/d/optout.

Jan Monterrubio

unread,
Apr 5, 2019, 12:47:35 PM4/5/19
to jenkins...@googlegroups.com
We use the JOB_URL variable to create a link to a published site, like " ${JOB_URL}/site/index.html". Would that variable give you enough context of where you want to direct people to?

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.

Viacheslav Dubrovskyi

unread,
Apr 10, 2019, 9:57:40 AM4/10/19
to jenkins...@googlegroups.com

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 пишет:
--
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.

For more options, visit https://groups.google.com/d/optout.
-- 
WBD,
Viacheslav Dubrovskyi

monger_39

unread,
Apr 11, 2019, 7:50:48 AM4/11/19
to jenkins...@googlegroups.com
Hi Viacheslav
thx 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.

Viacheslav Dubrovskyi

unread,
Apr 11, 2019, 9:46:52 AM4/11/19
to jenkins...@googlegroups.com

Hi monger_39,

Look to this issue https://issues.jenkins-ci.org/browse/JENKINS-28119


11.04.2019 14:50, 'monger_39' via Jenkins Users пишет:

For more options, visit https://groups.google.com/d/optout.
-- 
WBD,
Viacheslav Dubrovskyi

monger_39

unread,
Apr 18, 2019, 5:32:31 AM4/18/19
to jenkins...@googlegroups.com
Hi,
thx for the hint about issue https://issues.jenkins-ci.org/browse/JENKINS-28119 . Just added a comment about my use-case.
gr, M

 




Reply all
Reply to author
Forward
0 new messages