Using Jenkins gitlab token to make an API call From inside a Jenkins pipeline, I want to create a merge request on gitlab

def toJson = {
    input -&gt;
    groovy.json.JsonOutput.toJson(input)
}
def body = [
    private_token: "...",
    source_branch: "...",
    target_branch: "...",
    title: "..."
]
httpRequest httpMode: 'POST', requestBody: toJson(body), contentType: 'APPLICATION_JSON', url: 'https://my.gitlab.domain/api/v4/projects/1234/merge_requests'


My problem is with the private_token, I don't want to put it in clear in the Jenkinsfile.

I didn't found a way to get it from Jenkins credentials, is there one ?
Try something similar to the following:

environment {
  GITLAB_API_TOKEN = credentials('gitlab_api_token').   
}


or

withCredentials([[
  $class: 'com.dabsquared.gitlabjenkins.connection.GitLabApiTokenImpl',
  credentialsId: 'gitlab_api_token',
  variable: 'GITLAB_API_TOKEN'
]])


See https://jenkins.io/doc/pipeline/steps/credentials-binding/
and  https://github.com/jenkinsci/gitlab-plugin/issues/536 for more information.