Gitlab-plugin: Support pipeline build state : 'skipped'

Created on 21 Dec 2018  路  6Comments  路  Source: jenkinsci/gitlab-plugin

Issue

Context

  • Gitlab plugin version: 1.5.11
  • Gitlab version: 11.5.3
  • Jenkins version: 2.156
  • Job type: Pipeline.

Logs & Traces

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 24: Expecting "class com.dabsquared.gitlabjenkins.gitlab.api.model.BuildState" for parameter "state" but got "skipped" of type class java.lang.String instead @ line 24, column 55.
   itStatus name: 'test', state: 'skipped'
                                 ^

1 error

    at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
    at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1085)
    at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
    at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
    at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
    at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
    at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
    at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
    at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:131)
    at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:125)
    at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:560)
    at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:521)
    at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:320)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:429)

Problem description

We have a pipeline job which at the moment skips the 'Test' Stage. As per Gitlab docs, following are valid states:

The status of pipelines, one of: running, pending, success, failed, canceled, skipped

However when using skipped as a state, GitLab Plugin raises the above exception.

Possible root cause:
skipped should be added as an enum under com.dabsquared.gitlabjenkins.gitlab.api.model.BuildState in this file:
https://github.com/jenkinsci/gitlab-plugin/blob/master/src/main/java/com/dabsquared/gitlabjenkins/gitlab/api/model/BuildState.java

awaiting feedback

Most helpful comment

@lavock @Kiran-B
Problem is we are working with commit statuses, not Gitlab pipelines, even if the Gitlab UI shows them as pipelines. Unfortunately, the skipped status does not exists for commit builds.

See #811 and Gitlab API Doc

You can follow this issue on Gitlab as well.

All 6 comments

This should already be supported. See https://github.com/jenkinsci/gitlab-plugin#scripted-pipeline-jobs Can you share your Pipeline code so I can see if there is a syntax error with it?

Apologies for the delayed response.
Below is the constricted version of the pipeline code. I have only retained the first two stages of the pipeline. Note that the below pipeline code works if skipped is replaced by success in this line:

updateGitlabCommitStatus name: 'test', state: 'skipped'

pipeline {
  agent { label 'mac' }

  environment {
    TEST_STAGE_STATUS = 'failed'
    BUILD_STAGE_STATUS = 'failed'
    DEPLOY_STAGE_STATUS = 'failed'
  }

  options {
    gitLabConnection('Gitlab')
    gitlabBuilds(builds: ['build', 'test', 'deploy'])
  }

  triggers {
    gitlab(triggerOnPush: true, triggerOnMergeRequest: true, branchFilterType: 'All')
  }

  stages {

    stage ('Clean the Workspace') {
      steps {
        deleteDir()
        // IMPORTANT: 
        // Comment below line to avoid https://github.com/jenkinsci/gitlab-plugin/issues/874
        updateGitlabCommitStatus name: 'test', state: 'skipped'
        // updateGitlabCommitStatus name: 'test', state: 'success'
        updateGitlabCommitStatus name: 'build', state: 'pending'
        updateGitlabCommitStatus name: 'deploy', state: 'pending'
      }
    }

    stage ('Checkout') {
      steps {
        checkout changelog: true,
        poll: true,
        scm: [$class: 'GitSCM',
          branches: [[name: 'origin/${sourceBranch}']],
          browser: [$class: 'GitLab', repoUrl: 'https://example.com/root/my-repo', version: '11.5'],
          doGenerateSubmoduleConfigurations: false,
          extensions:  [[$class: 'CleanBeforeCheckout']],
          submoduleCfg: [],
          userRemoteConfigs: [[credentialsId: 'AABC1529-CF84-4B91-9A43-580CD2ADD27C', url: '[email protected]:root/my-repo.git']]
        ]
      }
    }

  post {
      failure {
      updateGitlabCommitStatus name: 'test', state: "${env.TEST_STAGE_STATUS}"
      updateGitlabCommitStatus name: 'build', state: "${env.BUILD_STAGE_STATUS}"
      updateGitlabCommitStatus name: 'deploy', state: "${env.DEPLOY_STAGE_STATUS}"
    }
  }
}

I had mentioned the incorrect state in the title(though it was correct in the description). I have now corrected the title.

I think i dont understand something. It was added and then removed by the same guy :

@semos

removed skipped step

Skipped step is only available on pipelines APIs

I would love some further explanations ^^'.

@lavock @Kiran-B
Problem is we are working with commit statuses, not Gitlab pipelines, even if the Gitlab UI shows them as pipelines. Unfortunately, the skipped status does not exists for commit builds.

See #811 and Gitlab API Doc

You can follow this issue on Gitlab as well.

Thanks a lot for the info @semos

Thanks @lavock for digging into this.

Apologies. I had not realized this plugin used commit status APIs.
Closing this issue as the same is a duplicate of #811

Was this page helpful?
0 / 5 - 0 ratings