jenkinsci / gitlab-plugin

A Jenkins plugin for interfacing with GitLab
https://plugins.jenkins.io/gitlab-plugin/
GNU General Public License v2.0
1.44k stars 618 forks source link

Error with Manual build #837

Open AntoineConffx opened 6 years ago

AntoineConffx commented 6 years ago

Issue

Context

Logs & Traces

Jenkins Log for Gitlab plugin with all log levels enabled.


Sep 17, 2018 12:16:02 PM INFO com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
Retrieving gitlab project ids
Sep 17, 2018 12:16:02 PM INFO com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
Build does not contain SCM revision action.
Sep 17, 2018 12:16:02 PM INFO com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
Retrieving gitlab project ids
Sep 17, 2018 12:16:02 PM INFO com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
Build does not contain SCM revision action.
Sep 17, 2018 12:16:02 PM INFO com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
Retrieving gitlab project ids
Sep 17, 2018 12:16:02 PM INFO com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
Build does not contain SCM revision action.

Problem description

I current have 2 jobs for 2 different Gitlab projects. Both are set up to be triggered via webhook, listening to merge request and notes hooks. They both work perfectly well and they update build status on Merge requests. My current issue happens with trying to build the projects manually. The job is not parametrized and when triggering manually I just want to build master + post the commit status on the master branch. One of those projects can be built manually and it successfully posts the commit status to the master branch, while the other fails to commit status updates with an error related to missing Build action in gitlabCommitStatus retrieveGitlabProjectIds (Show in Jenkins log above). How would I go on about fixing an issue like that? I've compared the build.xml files of both projects and they're the same. I can post more info as needed

AntoineConffx commented 6 years ago

Do I need to provide more information for this?

Thanks :)

omehegan commented 6 years ago

@AntoineConffx no, just have not had time to look at it yet.

AntoineConffx commented 6 years ago

@omehegan no worries I'm not pressing for time or anything was just wondering if I was missing anything :)

omehegan commented 6 years ago

@AntoineConffx can you please attach the two config.xml files for your jobs? It seems that one job does not think there is any git repo configured or any git checkout happening.

AntoineConffx commented 6 years ago

@omehegan Sure thing.

This is the config for the job that can build manually and post the build status.


<?xml version='1.1' encoding='UTF-8'?>
<flow-definition plugin="workflow-job@2.25">
  <actions/>
  <description>Builds Gitlab repo and reports back build status.&#xd;
Automatically triggered from non WIP Merge requests&#xd;
Manual Triggered by commenting on Merge request: Jenkins rebuild</description>
  <keepDependencies>false</keepDependencies>
  <properties>
    <com.coravy.hudson.plugins.github.GithubProjectProperty plugin="github@1.29.2">
      <projectUrl>http://Gitlab-Server/Project/</projectUrl>
      <displayName>Project-Title</displayName>
    </com.coravy.hudson.plugins.github.GithubProjectProperty>
    <com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty plugin="gitlab-plugin@1.5.10">
      <gitLabConnection>Connection_Name</gitLabConnection>
    </com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty>
    <org.jenkinsci.plugins.gitlablogo.GitlabLogoProperty plugin="gitlab-logo@1.0.3">
      <repositoryName></repositoryName>
    </org.jenkinsci.plugins.gitlablogo.GitlabLogoProperty>
    <org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
      <triggers>
        <com.dabsquared.gitlabjenkins.GitLabPushTrigger plugin="gitlab-plugin@1.5.10">
          <spec></spec>
          <triggerOnPush>false</triggerOnPush>
          <triggerOnMergeRequest>true</triggerOnMergeRequest>
          <triggerOnPipelineEvent>false</triggerOnPipelineEvent>
          <triggerOnAcceptedMergeRequest>false</triggerOnAcceptedMergeRequest>
          <triggerOnClosedMergeRequest>false</triggerOnClosedMergeRequest>
          <triggerOnApprovedMergeRequest>false</triggerOnApprovedMergeRequest>
          <triggerOpenMergeRequestOnPush>never</triggerOpenMergeRequestOnPush>
          <triggerOnNoteRequest>true</triggerOnNoteRequest>
          <noteRegex>.*[Jj]enkins [Rr]ebuild*</noteRegex>
          <ciSkip>true</ciSkip>
          <skipWorkInProgressMergeRequest>true</skipWorkInProgressMergeRequest>
          <setBuildDescription>true</setBuildDescription>
          <branchFilterType>All</branchFilterType>
          <includeBranchesSpec></includeBranchesSpec>
          <excludeBranchesSpec></excludeBranchesSpec>
          <sourceBranchRegex></sourceBranchRegex>
          <targetBranchRegex></targetBranchRegex>
          <secretToken>{Secret-Token}</secretToken>
          <pendingBuildName></pendingBuildName>
          <cancelPendingBuildsOnUpdate>true</cancelPendingBuildsOnUpdate>
        </com.dabsquared.gitlabjenkins.GitLabPushTrigger>
      </triggers>
    </org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
  </properties>
  <definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition" plugin="workflow-cps@2.55">
    <script>//Example scripts
//https://jenkins.io/doc/pipeline/examples/#trigger-job-on-all-nodes
//
def BuildAndTest(nodeName, OutputName)
{
  def failureDetected = false
  timeout(time: 2, unit: &apos;HOURS&apos;) 
  {
      gitlabBuilds(builds: [&quot;Build &quot; + OutputName]) 
      {
        node(nodeName)
        {
          stage (&quot;Checkout &quot; + OutputName)
          { 
            if (env.gitlabMergeRequestId) 
            {
              checkout changelog: true, poll: true, scm: [
                  $class: &apos;GitSCM&apos;, 
                  branches: [[name: &quot;origin/${env.gitlabSourceBranch}&quot;]],
                  doGenerateSubmoduleConfigurations: false, 
                  extensions: [
                      [$class: &apos;PreBuildMerge&apos;, options: [fastForwardMode: &apos;NO_FF&apos;, mergeRemote: &apos;origin&apos;, mergeStrategy: &apos;DEFAULT&apos;, mergeTarget: &quot;${env.gitlabTargetBranch}&quot;]],
                      [$class: &apos;RelativeTargetDirectory&apos;, relativeTargetDir: &apos;./Project&apos;],
                      [$class: &apos;SubmoduleOption&apos;, disableSubmodules: false, parentCredentials: true, recursiveSubmodules: true, reference: &apos;&apos;, trackingSubmodules: true],
                      [$class: &apos;AuthorInChangelog&apos;]
                  ],
                  submoduleCfg: [], 
                  userRemoteConfigs: [[credentialsId: &apos;Jenkins_Credentials&apos;, url: &apos;http://Gitlab-Server/Project.git&apos;]]
                  ]
              checkout changelog: false, scm: [
                $class: &apos;SubversionSCM&apos;, 
                additionalCredentials: [], 
                excludedCommitMessages: &apos;&apos;, 
                excludedRegions: &apos;&apos;, 
                excludedRevprop: &apos;&apos;, 
                excludedUsers: &apos;&apos;, 
                filterChangelog: false, 
                ignoreDirPropChanges: false, 
                includedRegions: &apos;&apos;, 
                locations: 
                  [[
                    cancelProcessOnExternalsFail: true, 
                    credentialsId: &apos;Credentials&apos;, 
                    depthOption: &apos;infinity&apos;, 
                    ignoreExternalsOption: true, 
                    local: &apos;./Second-Project&apos;, 
                    remote: &apos;https://Svn-Server/Second-Project&apos;
                  ]], 
                quietOperation: true, workspaceUpdater: [$class: &apos;UpdateUpdater&apos;]]
              }
              else
              {
                checkout changelog: true, poll: true, scm: [
                    $class: &apos;GitSCM&apos;, 
                        branches: [[name: &quot;origin/master&quot;]],
                        doGenerateSubmoduleConfigurations: false, 
                        extensions: [
                                [$class: &apos;RelativeTargetDirectory&apos;, relativeTargetDir: &apos;./Project&apos;],
                                [$class: &apos;SubmoduleOption&apos;, disableSubmodules: false, parentCredentials: true, recursiveSubmodules: true, reference: &apos;&apos;, trackingSubmodules: true],
                                [$class: &apos;AuthorInChangelog&apos;]
                            ],
                        submoduleCfg: [], 
                        userRemoteConfigs: [[credentialsId: &apos;Jenkins_Credentials&apos;, url: &apos;http://Gitlab-Server/Project.git&apos;]]
                ]
                checkout changelog: false, scm: [
                  $class: &apos;SubversionSCM&apos;, 
                  additionalCredentials: [], 
                  excludedCommitMessages: &apos;&apos;, 
                  excludedRegions: &apos;&apos;, 
                  excludedRevprop: &apos;&apos;, 
                  excludedUsers: &apos;&apos;, 
                  filterChangelog: false, 
                  ignoreDirPropChanges: false, 
                  includedRegions: &apos;&apos;, 
                  locations: 
                    [[
                      cancelProcessOnExternalsFail: true, 
                      credentialsId: &apos;Credentials&apos;, 
                      depthOption: &apos;infinity&apos;, 
                      ignoreExternalsOption: true, 
                    local: &apos;./Second-Project&apos;, 
                    remote: &apos;https://Svn-Server/Second-Project&apos;
                    ]], 
                  quietOperation: true, workspaceUpdater: [$class: &apos;UpdateUpdater&apos;]]             
              }
          }
          stage(&quot;Build &quot; + OutputName) 
          { 
            gitlabCommitStatus(name: &quot;Build &quot; + OutputName)
            {
              def statusCode = -1            
              //cho pwd 
              statusCode = bat returnStatus: true, script: &apos;python -u build.py&apos;
              if(statusCode != 0)
              {
                currentBuild.result = &apos;FAILURE&apos;
                updateGitlabCommitStatus name: &quot;Build &quot; + OutputName, state: &apos;failed&apos;
                error &quot;Failed Building the project on ${OutputName} with status code: ${statusCode}&quot;
              }
              else
                  currentBuild.result = &apos;SUCCESS&apos;
            }                
          }
        }
      } 
  }
}
try
{
    BuildAndTest(&apos;Windows&apos;, &apos;Windows&apos;);
    currentBuild.result = &apos;SUCCESS&apos;
}
catch (error)
{
    currentBuild.result = &apos;FAILURE&apos;
    throw error
}
</script>
    <sandbox>true</sandbox>
  </definition>
  <triggers/>
  <disabled>false</disabled>
</flow-definition>

This is the config of the job that fails to post the status when being triggered manually.


<?xml version='1.1' encoding='UTF-8'?>
<flow-definition plugin="workflow-job@2.26">
  <actions/>
  <description>The-Forge from Gitlab.&#xd;
&#xd;
Builds Gitlab repo and reports back build status.&#xd;
Automatically triggered from non WIP Merge requests&#xd;
Manual Triggered by commenting on Merge request: Jenkins rebuild
</description>
  <keepDependencies>false</keepDependencies>
  <properties>
    <com.coravy.hudson.plugins.github.GithubProjectProperty plugin="github@1.29.3">
      <projectUrl>http://Gitlab-Server/Project/</projectUrl>
      <displayName>Project_Name</displayName>
    </com.coravy.hudson.plugins.github.GithubProjectProperty>
    <com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty plugin="gitlab-plugin@1.5.10">
      <gitLabConnection>Connection_Name</gitLabConnection>
    </com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty>
    <org.jenkinsci.plugins.gitlablogo.GitlabLogoProperty plugin="gitlab-logo@1.0.3">
      <repositoryName></repositoryName>
    </org.jenkinsci.plugins.gitlablogo.GitlabLogoProperty>
    <org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
      <triggers>
        <com.dabsquared.gitlabjenkins.GitLabPushTrigger plugin="gitlab-plugin@1.5.10">
          <spec></spec>
          <triggerOnPush>false</triggerOnPush>
          <triggerOnMergeRequest>true</triggerOnMergeRequest>
          <triggerOnPipelineEvent>false</triggerOnPipelineEvent>
          <triggerOnAcceptedMergeRequest>false</triggerOnAcceptedMergeRequest>
          <triggerOnClosedMergeRequest>false</triggerOnClosedMergeRequest>
          <triggerOnApprovedMergeRequest>false</triggerOnApprovedMergeRequest>
          <triggerOpenMergeRequestOnPush>never</triggerOpenMergeRequestOnPush>
          <triggerOnNoteRequest>true</triggerOnNoteRequest>
          <noteRegex>.*[Jj]enkins [Rr]ebuild*</noteRegex>
          <ciSkip>true</ciSkip>
          <skipWorkInProgressMergeRequest>true</skipWorkInProgressMergeRequest>
          <setBuildDescription>true</setBuildDescription>
          <branchFilterType>All</branchFilterType>
          <includeBranchesSpec></includeBranchesSpec>
          <excludeBranchesSpec></excludeBranchesSpec>
          <sourceBranchRegex></sourceBranchRegex>
          <targetBranchRegex></targetBranchRegex>
          <secretToken>{Secret-Token-Value}</secretToken>
          <pendingBuildName></pendingBuildName>
          <cancelPendingBuildsOnUpdate>true</cancelPendingBuildsOnUpdate>
        </com.dabsquared.gitlabjenkins.GitLabPushTrigger>
      </triggers>
    </org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
  </properties>
  <definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition" plugin="workflow-cps@2.59">
    <script>//Example scripts
//https://jenkins.io/doc/pipeline/examples/#trigger-job-on-all-nodes
//
def BuildAndTest(nodeName, OutputName, isXbox)
{
    def failureDetected = false
    timeout(time: 2, unit: &apos;HOURS&apos;) 
    {
        gitlabBuildsList = [&quot;Build &quot; + OutputName, &quot;Test &quot; + OutputName]
        if(isXbox)
          gitlabBuildsList = [&quot;Build &quot; + OutputName]

        gitlabBuilds(builds: gitlabBuildsList) 
        {
          node(nodeName)
          {
              stage (&quot;Checkout &quot; + OutputName)
              {
                  if (env.gitlabMergeRequestId) {
                      checkout changelog: true, poll: true, scm: [
                          $class: &apos;GitSCM&apos;, 
                          branches: [[name: &quot;origin/${env.gitlabSourceBranch}&quot;]],
                          doGenerateSubmoduleConfigurations: false, 
                          extensions: [
                              [$class: &apos;PreBuildMerge&apos;, options: [fastForwardMode: &apos;NO_FF&apos;, mergeRemote: &apos;origin&apos;, mergeStrategy: &apos;DEFAULT&apos;, mergeTarget: &quot;${env.gitlabTargetBranch}&quot;]],
                              [$class: &apos;RelativeTargetDirectory&apos;, relativeTargetDir: &apos;./Project&apos;],
                              [$class: &apos;SubmoduleOption&apos;, disableSubmodules: false, parentCredentials: true, recursiveSubmodules: true, reference: &apos;&apos;, trackingSubmodules: true],
                              [$class: &apos;AuthorInChangelog&apos;]
                            // [$class: &apos;CleanBeforeCheckout&apos;]
                          ],
                          submoduleCfg: [], 
                          userRemoteConfigs: [[credentialsId: &apos;Jenkins_gitlab&apos;, url: &apos;http://Gitlab-Server/Project.git&apos;]]
                          ]
                      checkout changelog: true, poll: true, scm: [
                          $class: &apos;GitSCM&apos;, 
                          branches: [[name: &apos;*/master&apos;]], 
                          doGenerateSubmoduleConfigurations: false, 
                          extensions: [
                              [$class: &apos;RelativeTargetDirectory&apos;, relativeTargetDir: &apos;./SecondProject&apos;],
                              [$class: &apos;AuthorInChangelog&apos;],
                              [$class: &apos;CleanBeforeCheckout&apos;]
                          ],
                          submoduleCfg: [], 
                          userRemoteConfigs: [[credentialsId: &apos;Jenkins_gitlab&apos;, url: &apos;http://Gitlab-Server/Second_Project.git&apos;]]
                          ]
                  }
                  else
                  {
                      checkout changelog: true, poll: true, scm: [
                          $class: &apos;GitSCM&apos;, 
                              branches: [[name: &apos;origin/master&apos;]], 
                              doGenerateSubmoduleConfigurations: false, 
                              extensions: [
                                  [$class: &apos;RelativeTargetDirectory&apos;, relativeTargetDir: &apos;./SecondProject&apos;],
                                  [$class: &apos;AuthorInChangelog&apos;]],
                              submoduleCfg: [], 
                              userRemoteConfigs: [[credentialsId: &apos;Jenkins_gitlab&apos;, url: &apos;http://Gitlab-Server/Second_Project.git&apos;]]
                      ]
                      scmVars = checkout changelog: true, poll: true, scm: [
                          $class: &apos;GitSCM&apos;, 
                              branches: [[name: &quot;origin/master&quot;]],
                              doGenerateSubmoduleConfigurations: false, 
                              extensions: [
                                      [$class: &apos;RelativeTargetDirectory&apos;, relativeTargetDir: &apos;./Project&apos;],
                                      [$class: &apos;SubmoduleOption&apos;, disableSubmodules: false, parentCredentials: true, recursiveSubmodules: true, reference: &apos;&apos;, trackingSubmodules: true],
                                      [$class: &apos;AuthorInChangelog&apos;]
                                  ],
                              submoduleCfg: [], 
                              userRemoteConfigs: [[credentialsId: &apos;Jenkins_gitlab&apos;, url: &apos;http://Gitlab-Server/Project.git&apos;]]
                      ]
                  }
              }

                stage(&quot;Build &quot; + OutputName) 
                { 
                    gitlabCommitStatus(name: &quot;Build &quot; + OutputName)
                    {
                        def statusCode = -1
                        if (isUnix())
                        {
                            statusCode = sh returnStatus: true, script: &apos;python build.py;
                            if(statusCode != 0)
                            {
                                failureDetected = true
                                echo &quot;Failed Building the project on ${OutputName} with status code: ${statusCode}&quot;
                            }
                        }
                        else
                        {
                            //cho pwd 
                            if(isXbox)
                              statusCode = bat returnStatus: true, script: &apos;python build.py&quot;
                            else
                              statusCode = bat returnStatus: true, script: &apos;python build.py&quot;

                            if(statusCode != 0)
                            {
                                failureDetected = true
                                echo &quot;Failed Building the project on ${OutputName} with status code: ${statusCode}&quot;
                            }
                        }  
                    }                
                }
                if(!isXbox)
                {
                  stage(&quot;Test &quot; + OutputName) 
                  {
                    gitlabCommitStatus(name: &quot;Test &quot; + OutputName)
                    {
                      if(failureDetected == true)
                      {
                        updateGitlabCommitStatus name: &quot;Build &quot; + OutputName, state: &apos;failed&apos;
                        updateGitlabCommitStatus name: &quot;Test &quot; + OutputName, state: &apos;canceled&apos;
                        error &quot;Failed Building the project on ${OutputName}&quot;
                      }

                      def statusCode = -1
                      if (isUnix())
                      {
                        statusCode =bat returnStatus: true, script: &apos;python build.py;
                        if(statusCode != 0)
                        {
                            currentBuild.result = &apos;FAILURE&apos;
                            error &quot;Failed Testing the project on ${OutputName} with status code: ${statusCode}&quot;
                        }
                        else
                            currentBuild.result = &apos;SUCCESS&apos;
                      }
                      else
                      {
                        //cho pwd 
                        statusCode =bat returnStatus: true, script: &apos;python build.py;
                        if(statusCode != 0)
                        {
                            currentBuild.result = &apos;FAILURE&apos;
                            error &quot;Failed Testing the project on ${OutputName} with status code: ${statusCode}&quot;
                        }
                        else
                            currentBuild.result = &apos;SUCCESS&apos;
                      }
                    }                
                  }
                }
                else
                {
                    if(failureDetected == true)
                    {
                      updateGitlabCommitStatus name: &quot;Build &quot; + OutputName, state: &apos;failed&apos;
                      error &quot;Failed Building the project on ${OutputName}&quot;
                      currentBuild.result = &apos;FAILURE&apos;
                    }
                    else
                      currentBuild.result = &apos;SUCCESS&apos;
                }
              }
          } 
    }
}

try
{
    parallel    &apos;Mac&apos;: {BuildAndTest(&apos;Apple&apos;, &apos;Apple&apos;, false)},
                &apos;Ubuntu&apos;: {BuildAndTest(&apos;Ubuntu&apos;, &apos;Ubuntu&apos;, false)},
                &apos;Windows&apos;: {BuildAndTest(&apos;GoldDigger&apos;, &apos;Windows&apos;, false)},
                &apos;Xbox&apos;: {BuildAndTest(&apos;Xbox&apos;, &apos;Xbox&apos;, true)},
                failFast : false
    currentBuild.result = &apos;SUCCESS&apos;
}
catch (error)
{
    currentBuild.result = &apos;FAILURE&apos;
    throw error
}
</script>
    <sandbox>true</sandbox>
  </definition>
  <triggers/>
  <disabled>false</disabled>
</flow-definition>

Note: They both work with comments on merge requests or a push event to a merge request.

AntoineConffx commented 6 years ago

Looks like the main difference between the 2 are the following plugin versions: github, workflow-jobs and workflow-cps plugins.

omehegan commented 5 years ago

@AntoineConffx sorry for the late reply. It is a bit hard for me to parse your Pipeline code, so I can't be sure of what is going on here. For one thing, I see that you are mixing gitlabCommitStatus and updateGitlabCommitStatus. I think you should only need to use one or the other. The second one just gives you more control over exactly what status is sent at any given point, whereas the first just sends pending/success/failure IIRC based on the state of the build when the block opens and closes. I am also wondering if the Build does not contain SCM revision action messages you see in the log are not relevant to the issue at hand.

However, you say that the issue is only with the one job when it is run manually. That suggests to me that, at the point when the job is trying to send the status to GitLab, it has not yet checked out the specific ref where the job status message would need to be sent. Because you are using multiple "send status" steps, I can't figure out which one is firing improperly in that job. I would suggest that you add some print debug statements to the Pipeline to try and narrow that down, as that should then help us make sense of what the state of the job is at that point.

AntoineConffx commented 5 years ago

@omehegan No worries I appreciate you coming back to me 👍 It's really not a priority but I'm nit-picky and would like to fix it.

Those are great suggestions and as for the usage of both commitStatus functions I'll try to use just one or the other and see what happens.

Will let you know when I try it out

fragpit commented 5 years ago

Same here. Two Jenkins servers w/ GitLab plugin installed. Both updated to same/latest version of plugins and server. (installed plugin list is different). One works perfectly (freestyle or pipeline) another one works only with freestyle job. When starting pipeline I see this log:

May 31, 2019 5:26:13 PM INFO com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
Retrieving gitlab project ids
May 31, 2019 5:26:13 PM INFO com.dabsquared.gitlabjenkins.util.CommitStatusUpdater retrieveGitlabProjectIds
Build does not contain SCM revision action.
ShoJinto commented 2 years ago

我也遇到了同样的问题, image 以上是我的jenkinsfile脚本片段。Jenkins的log: image 请问有修复计划么?

schwaerz commented 1 year ago

Same issue using the following simple pipeline:

node('JDK8') {
    checkout scm
    gitlabCommitStatus {
        bat 'echo foo'
    }
}

I did not get it running at all, so far.

Hope there is still someone looking into it?

Please note that I used 'replay' to test the gitlabCommitStatus step. Maybe it does not like being called from a replay?

krisstern commented 1 year ago

I don't have the bandwidth to check things yet but will come back to this later within the next few weeks.