'Jenkins fails to post build status to gitlab,Pipelines shows up pending status.This is a multibranch pipeline

I tried all the possible solutions available online. Changed my token with all permissions. Changed the gitlab connection with latest token. Still pipelines in gitlab shows the pending status. These are the logs from jenkins.

Mar 23, 2022 5:37:19 PM INFO com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
Retrieving gitlab project ids
Mar 23, 2022 5:37:19 PM WARNING com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
No gitlab client found.
Mar 23, 2022 5:38:13 PM INFO com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
Retrieving gitlab project ids
Mar 23, 2022 5:38:13 PM WARNING com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
No gitlab client found.
Mar 23, 2022 5:38:13 PM INFO com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
Retrieving gitlab project ids
Mar 23, 2022 5:38:13 PM WARNING com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
No gitlab client found.
Mar 23, 2022 5:38:14 PM INFO com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
Retrieving gitlab project ids
Mar 23, 2022 5:38:14 PM WARNING com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
No gitlab client found.
Mar 23, 2022 5:38:14 PM INFO com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
Retrieving gitlab project ids
Mar 23, 2022 5:38:14 PM WARNING com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
No gitlab client found.
Mar 23, 2022 5:38:14 PM INFO com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
Retrieving gitlab project ids
Mar 23, 2022 5:38:14 PM WARNING com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
No gitlab client found.
Mar 23, 2022 5:38:15 PM INFO org.jenkinsci.plugins.workflow.job.WorkflowRun finish
multi/pipelines-check #79 completed: SUCCESS
Mar 23, 2022 5:38:15 PM INFO io.jenkins.plugins.generic.event.HttpEventSender send
Skipped event sending due to receiver URL not set
Mar 23, 2022 5:38:16 PM WARNING jenkins.util.Listeners lambda$notify$0
null
java.lang.NullPointerException
    at io.jenkins.plugins.gitlabbranchsource.helpers.GitLabPipelineStatusNotifier.lambda$getStatusName$0(GitLabPipelineStatusNotifier.java:102)
    at java.logging/java.util.logging.Logger.log(Logger.java:1050)
    at io.jenkins.plugins.gitlabbranchsource.helpers.GitLabPipelineStatusNotifier.getStatusName(GitLabPipelineStatusNotifier.java:101)
    at io.jenkins.plugins.gitlabbranchsource.helpers.GitLabPipelineStatusNotifier.getStatusName(GitLabPipelineStatusNotifier.java:84)
    at io.jenkins.plugins.gitlabbranchsource.helpers.GitLabPipelineStatusNotifier.logComment(GitLabPipelineStatusNotifier.java:178)
    at io.jenkins.plugins.gitlabbranchsource.helpers.GitLabPipelineStatusNotifier.access$500(GitLabPipelineStatusNotifier.java:52)
    at io.jenkins.plugins.gitlabbranchsource.helpers.GitLabPipelineStatusNotifier$JobCompletedListener.onCompleted(GitLabPipelineStatusNotifier.java:484)
    at hudson.model.listeners.RunListener.lambda$fireCompleted$0(RunListener.java:207)
    at jenkins.util.Listeners.lambda$notify$0(Listeners.java:59)
    at jenkins.util.Listeners.notify(Listeners.java:67)
    at hudson.model.listeners.RunListener.fireCompleted(RunListener.java:205)
    at org.jenkinsci.plugins.workflow.job.WorkflowRun.finish(WorkflowRun.java:627)
    at org.jenkinsci.plugins.workflow.job.WorkflowRun.access$800(WorkflowRun.java:138)
    at org.jenkinsci.plugins.workflow.job.WorkflowRun$GraphL.onNewHead(WorkflowRun.java:1049)
    at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.notifyListeners(CpsFlowExecution.java:1474)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$3.run(CpsThreadGroup.java:497)
    at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$1.run(CpsVmExecutorService.java:38)
    at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:139)
    at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
    at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)

JENKINSFILE:

pipeline {
  agent {label 'xxx'}
  options {
     gitLabConnection('xxx')
          }

  stages {
     stage('Code') {
            steps {
            gitlabCommitStatus(connection:     gitLabConnection(gitLabConnection: 'xxx', jobCredentialId: 'xxx-xxx-xxx-xxx-xxxxx', useAlternativeCredential: true), name: 'Code_checkout') {
          checkout([$class: 'GitSCM', branches: [[name: '*/develop']], extensions: [[$class: 'GitLFSPull'], [$class: 'RelativeTargetDirectory', relativeTargetDir: 'xxxxxx']], userRemoteConfigs: [[url: '[email protected]:xxxxx/xxxxxx/root.git']]])
              sh'''
              cd xxxxxxxxx
              git submodule update --init --recursive
              cd /home/jenkins/jenkins_slave/workspace/ROOT/vds
              git checkout develop
              git pull
              cd xxxxxxxxxxx
              '''
              }
            }
     }
     stage('Testing') {
            steps {
                gitlabCommitStatus(connection:     gitLabConnection(gitLabConnection: 'xxxxxx', jobCredentialId: 'xxxxxxx', useAlternativeCredential: true), name: 'Testing') {
                echo "checking"
            }
        }
   }
  }

all the code checkout part and testing part is happening in shell



Solution 1:[1]

You can use these two parameters in optionsblock

options {
    gitLabConnection('gitlab')
    gitlabBuilds(builds: ['build'])
}

and in post section you can use the updateGitlabCommitStatus like this

post {
    failure {
      updateGitlabCommitStatus name: 'build', state: 'failed'
    }
    unstable {
      updateGitlabCommitStatus name: 'build', state: 'failed'
    }
    aborted {
      updateGitlabCommitStatus name: 'build', state: 'canceled'
    }
    success {
      updateGitlabCommitStatus name: 'build', state: 'success'
    }
    always {
    }
}

For info checkout this section https://github.com/jenkinsci/gitlab-plugin/blob/master/README.md

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dashrath Mundkar