Operations 4 min read

Using Jenkins Pipeline Plugins: readJSON, withCredentials, checkout, publishHTML, input, BuildUser, and httpRequest

This guide demonstrates how to use several Jenkins Pipeline plugins—including readJSON, withCredentials, checkout, publishHTML, input, BuildUser, and httpRequest—to handle JSON data, manage credentials, retrieve source code, publish HTML reports, interactively collect input, obtain build user information, and perform HTTP requests within a CI/CD workflow.

DevOps Cloud Academy
DevOps Cloud Academy
DevOps Cloud Academy
Using Jenkins Pipeline Plugins: readJSON, withCredentials, checkout, publishHTML, input, BuildUser, and httpRequest

1. readJSON – processing JSON data To use the readJSON method you need the Pipeline Utility Steps plugin; it can parse JSON from a file or text.

def response = readJSON text: "${response.content}"
println(response[0]['name'])

You can also use native Groovy methods with @NonCPS to avoid serialization issues.

// Native method
import groovy.json.*
@NonCPS
def GetJson(text) {
    def prettyJson = JsonOutput.prettyPrint(text)
    new JsonSlurperClassic().parseText(prettyJson)
}

2. withCredentials – accessing stored credentials This step reads credentials stored in Jenkins by ID, allowing sensitive information to be used as variables during pipeline execution.

withCredentials([string(credentialsId: "xxxxx", variable: "sonarToken")]) {
    println(sonarToken)
}

3. checkout – retrieving source code Use the checkout step to pull code from Git or Subversion repositories, specifying branch, credentials, and repository URL.

// Git example
checkout([$class: 'GitSCM', branches: [[name: "branchName"]],
    doGenerateSubmoduleConfigurations: false,
    extensions: [], submoduleCfg: [],
    userRemoteConfigs: [[credentialsId: "${credentialsId}", url: "${srcUrl}"]]])

// SVN example
checkout([$class: 'SubversionSCM', additionalCredentials: [],
    filterChangelog: false, ignoreDirPropChanges: false,
    locations: [[credentialsId: "${credentialsId}", depthOption: 'infinity',
        ignoreExternalsOption: true, remote: "${svnUrl}"]],
    workspaceUpdater: [$class: 'CheckoutUpdater']])

4. publishHTML – publishing HTML reports The publishHTML plugin can display HTML reports such as unit‑test or automation results.

publishHTML([allowMissing: false,
    alwaysLinkToLastBuild: false,
    keepAll: true,
    reportDir: './report/',
    reportFiles: "a.html, b.html",
    reportName: 'InterfaceTestReport',
    reportTitles: 'HTML'])

5. input – interactive pipeline prompts The input step lets a user make choices (e.g., whether to deploy) with parameters like checkboxes, multi‑select, or text.

def result = input message: '选择xxxxx',
    ok: '提交',
    parameters: [extendedChoice(description: 'xxxxx',
        descriptionPropertyValue: '',
        multiSelectDelimiter: ',',
        name: 'failePositiveCases',
        quoteValue: false,
        saveJSONParameterToFile: false,
        type: 'PT_CHECKBOX',
        value: "1,2,3",
        visibleItemCount: 99)]
println(result)

6. BuildUser – obtaining the build initiator Wrap the step to echo the full name, user ID, and email of the person who triggered the build.

wrap([$class: 'BuildUser']) {
    echo "full name is $BUILD_USER"
    echo "user id is $BUILD_USER_ID"
    echo "user email is $BUILD_USER_EMAIL"
}

7. httpRequest – making HTTP calls Use this step to call external APIs, specifying authentication, content type, and URL.

ApiUrl = "http://xxxxxx/api/project_branches/list?project=${projectName}"
Result = httpRequest authentication: 'xxxxxxxxx',
    quiet: true,
    contentType: 'APPLICATION_JSON',
    url: "${ApiUrl}"
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

ci/cdDevOpsPipelineGroovyJenkins
DevOps Cloud Academy
Written by

DevOps Cloud Academy

Exploring industry DevOps practices and technical expertise.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.