Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-39644

Provide an API to access the current FlowNode from pipeline script

XMLWordPrintable

      Currently, one have to use some non-public (and probable not intended) API, from the pipeline script:

      String getCurrentFlowNodeID() {
          // Types explanation:
          //   CpsThread.current() : CpsThread
          //   .head               : FlowHead (final field access, no accessor method present)
          //   .get()              : FlowNode
          //   .getId()            : String
          return CpsThread.current().head.get().getId()
      }
      

      Background:

      We need a business-level view on certain customized pipeline aspects, but with the ability to dig lower into technical foundation.
      Therefor we need the ability to map between these customized aspects and (at least) the FlowNode where they occurred.
      We are "afraid" that the current approach using non-public API is not intended and may be changed or even get removed.

      FYI: we iterate post-mortem through builds/[num]/workflow/*.xml files to instantiate a simple data model view on the pipeline, which is then enriched with data from another bunch of our own *.xml files, where the customized business aspects are stored. Both kinds of XML data contain FlowNode IDs, so that they can be mapped together.

            Unassigned Unassigned
            iviat0r Ivan Ivanovich
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: