0

After a build completes, on the status page I can see details like started by user, this run spent, git commits etc. How do i add something to this page after build finishes. I want to capture a checkmarx scan result web link and add that to this status page.

I want to do this as part of my checkmarx stage after the scan runs or at the end with the post build actions.

I prefer not to install any custom plugins due to organizational restrictions

I tried the following but it didnt work:

// Groovy Postbuild Script
import hudson.model.*

def build = manager.build
def customMessage = "Custom message: " // my checkmarx link here

def changeSet = build.changeSet
def changes = changeSet.getItems().collect {
    "${it.author.fullName}: ${it.msg}"
}.join('\n')

def newContent = """
    <div>
        <h3>Custom Information:</h3>
        <p>${customMessage}</p>
        <h3>Changes:</h3>
        <pre>${changes}</pre>
    </div>
"""

def action = new ParametersAction([
    new StringParameterValue('CustomInformation', newContent)
])

build.addAction(action)

Any help in this regard is much appreciated

3
  • Does this answer your question? Jenkins pipeline plugin: set the build description Commented Mar 28, 2024 at 22:35
  • sorry no i am not using the buildDescription plugin and not planning to use it Commented Mar 29, 2024 at 22:05
  • it's not a plugin, it's a variable that Jenkins exposes by default. Commented Mar 29, 2024 at 23:11

1 Answer 1

0

You are on the right track, adding some kind of Action to the build is the first step. Actions are persisted with the rest of the build information in the build.xml file. Then the action is displayed on the build summary page using a corresponding View that can only come from either the Jenkins core or one of the plugins. You cannot supply that View as a part of your pipeline or shared library.

The only View I know that would display somewhat arbitrary text using just the Jenkins core is InterruptedBuildAction. It is limited to plain text only, so no links or any kind of formatting, and it prepends you messages with Exception:.

import jenkins.model.InterruptedBuildAction
import org.jenkinsci.plugins.workflow.steps.ExceptionCause

def call(Collection<String> messages) {
  def build = currentBuild.rawBuild
  def causesOfInterruption = messages.collect {
    new ExceptionCause(new Throwable(it))
  }
  def action = new InterruptedBuildAction(causesOfInterruption)
  build.addAction(action)
  build.save()
}

Try it and if the limitations bother you too much you will have to install some kind of plugin. I would recommend Badge.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.