Class BuildData

    • Method Detail

      • create

        @Nonnull
        public static BuildData create​(@Nullable
                                       Run<?,​?> run,
                                       @Nullable
                                       TaskListener listener)
        This is a workaround for a BuildData initialization issue.

        Some of the fields in this class are initialized with the values obtained from a Run instance. Querying Run fields can trigger run initialization in some cases (e.g. loading run data from disk when resuming a run after Jenkins restart). During run initialization some logs are written. Writing logs, in turn, requires creating a TaskListener associated with the run. Creating the listener triggers initialization of DatadogTaskListenerDecorator, as the listener's logger needs to be decorated. The decorator creates another BuildData instance, whose creation starts the whole cycle from the beginning. As the result, the code enters an endless cycle of initializing BuildData while initializing BuildData, which terminates with a stack overflow.

        The code below checks that BuildData for the provided run is already being created in the current thread. If that is the case, empty BuildData instance is returned for the nested calls in order to break the cycle. As a side effect, whatever logs are written while Run instance is being initialized will not be tagged with that run's data.

      • getTags

        public Map<String,​Set<String>> getTags()
        Assembles a map of tags containing: - Build Tags - Global Job Tags set in Job Properties - Global Tag set in Jenkins Global configuration
        Returns:
        a map containing all tags values
      • getJobName

        @Nonnull
        public String getJobName()
      • getBuildConfigurations

        @Nonnull
        public Map<String,​String> getBuildConfigurations()
      • isCompleted

        public boolean isCompleted()
      • isBuilding

        public boolean isBuilding()
      • setHostname

        public void setHostname​(String hostname)
      • getCharset

        public Charset getCharset()
      • getBuildNumber

        public String getBuildNumber​(String value)
      • getDuration

        public Long getDuration​(Long value)
      • getEndTime

        public Long getEndTime​(Long value)
      • getStartTime

        public Long getStartTime​(Long value)
      • getTotalQueueTimeMillis

        public long getTotalQueueTimeMillis()
        Returns the total time this build spent waiting in queue.
      • getVersion

        public Integer getVersion()
      • getTraceId

        public Long getTraceId()
      • getSpanId

        public Long getSpanId()
      • getUpstreamBuildTag

        @Nullable
        public String getUpstreamBuildTag​(String value)
      • getJenkinsUrl

        public String getJenkinsUrl​(String value)
      • setJenkinsUrl

        public void setJenkinsUrl​(String jenkinsUrl)
      • getExecutorNumber

        public String getExecutorNumber​(String value)
      • getWorkspace

        public String getWorkspace​(String value)
      • getGitCommit

        public String getGitCommit​(String value)
      • getGitMessage

        public String getGitMessage​(String value)
      • getGitAuthorName

        public String getGitAuthorName​(String value)
      • getGitAuthorEmail

        public String getGitAuthorEmail​(String value)
      • getGitCommitterName

        public String getGitCommitterName​(String value)
      • getGitCommitterEmail

        public String getGitCommitterEmail​(String value)
      • getGitAuthorDate

        public String getGitAuthorDate​(String value)
      • getGitCommitterDate

        public String getGitCommitterDate​(String value)
      • getGitDefaultBranch

        public String getGitDefaultBranch​(String value)
      • getPipelineDefinitionGitMetadata

        public GitMetadata getPipelineDefinitionGitMetadata()
        For multi-branch pipelines it is possible to check out pipeline definition from one repository, then, when executing the pipeline script, do another Git checkout from a different repository. This method returns Git metadata for original pipeline script checkout
      • getUserId

        public String getUserId()
      • getUserEmail

        public String getUserEmail​(String value)
      • getUpstreamPipelineUrl

        @Nullable
        public String getUpstreamPipelineUrl()
      • getUpstreamPipelineTraceId

        @Nullable
        public Long getUpstreamPipelineTraceId()
      • addLogAttributes

        public net.sf.json.JSONObject addLogAttributes()
      • isStartTimeKnown

        public boolean isStartTimeKnown()
        The accurate start time for a pipeline (WorkflowRun) is only known once the first step starts executing (everything before that counts as queued time: see the definition of propagatedMillisInQueue)