jenkinsci / violation-comments-to-gitlab-plugin

Comments GitLab merge requests with static code analyzer findings.
https://plugins.jenkins.io/violation-comments-to-gitlab
MIT License
20 stars 4 forks source link

Commenting/WIPing the merge request doesn't work #16

Closed stieglma closed 6 years ago

stieglma commented 6 years ago

After changing the configuration several times (authHeader true/false, private true/false, ...) It seems that I found a configuration for the plugin which allows jenkins to connect to gitlab. At least I don't get error messages which say otherwise. However the comments that should appear in the merge request, and setting the merge request to WIP doesn't happen. Do I do something wrong, or are there currently problems existing with the commenting stuff? Unfortunately I couldn't test with other options such as the maven connection because it seems to be broken, too cf. https://github.com/tomasbjerre/violation-comments-to-gitlab-maven-plugin/issues/1

This is the output i get:


--- Violation Comments to GitLab ---

gitLabUrl: ######### projectId: 211 mergeRequestIid: 289 apiToken: false apiTokenCredentialsId: true ignoreCertificateErrors: true apiTokenPrivate: true authMethodHeader: true createCommentWithAllSingleFileComments: false commentOnlyChangedContent: false minSeverity: INFO keepOldComments: false shouldSetWip: true FINDBUGS with pattern ./target/findbugsXml.xml$ Running Violation Comments To GitLab Merge request: 289 Workspace: ################# Found 2 violations from ViolationConfig [pattern=./target/findbugsXml.xml$, parser=FINDBUGS, reporter=Findbugs]. Will comment PR https://########## 211 289

This is the configuration I use:

ViolationsToGitLab([apiToken: '',
                                apiTokenCredentialsId: 'id',
                                apiTokenPrivate: true,
                                authMethodHeader: true,
                                gitLabUrl: '',
                                ignoreCertificateErrors: true,
                                keepOldComments: false,
                                mergeRequestIid: env.gitlabMergeRequestIid,
                                projectId: "211",
                                shouldSetWip: true,
                                commentOnlyChangedContent: false,
                                violationConfigs: [[parser: 'FINDBUGS', pattern: '.*/target/findbugsXml\\.xml$', reporter: 'Findbugs']]])
tomasbjerre commented 6 years ago

Did you perform the merge before doing analysis?

Den fre 15 juni 2018 13:58Thomas Stieglmaier notifications@github.com skrev:

After changing the configuration several times (authHeader true/false, private true/false, ...) It seems that I found a configuration for the plugin which allows jenkins to connect to gitlab. At least I don't get error messages which say otherwise. However the comments that should appear in the merge request, and setting the merge request to WIP doesn't happen. Do I do something wrong, or are there currently problems existing with the commenting stuff? Unfortunately I couldn't test with other options such as the maven connection because it seems to be broken, too cf. tomasbjerre/violation-comments-to-gitlab-maven-plugin#1 https://github.com/tomasbjerre/violation-comments-to-gitlab-maven-plugin/issues/1

This is the output i get:


--- Violation Comments to GitLab ---

gitLabUrl: ######### projectId: 211 mergeRequestIid: 289 apiToken: false apiTokenCredentialsId: true ignoreCertificateErrors: true apiTokenPrivate: true authMethodHeader: true createCommentWithAllSingleFileComments: false commentOnlyChangedContent: false minSeverity: INFO keepOldComments: false shouldSetWip: true FINDBUGS with pattern .

/target/findbugsXml.xml$ Running Violation Comments To GitLab Merge request: 289 Workspace: ################# Found 2 violations from ViolationConfig [pattern=./target/findbugsXml.xml$, parser=FINDBUGS, reporter=Findbugs]. Will comment PR https://########## 211 289

This is the configuration I use:

ViolationsToGitLab([apiToken: '', apiTokenCredentialsId: 'id', apiTokenPrivate: true, authMethodHeader: true, gitLabUrl: '', ignoreCertificateErrors: true, keepOldComments: false, mergeRequestIid: env.gitlabMergeRequestIid, projectId: "211", shouldSetWip: true, commentOnlyChangedContent: false, violationConfigs: [[parser: 'FINDBUGS', pattern: '.*/target/findbugsXml\.xml$', reporter: 'Findbugs']]])

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jenkinsci/violation-comments-to-gitlab-plugin/issues/16, or mute the thread https://github.com/notifications/unsubscribe-auth/AAa1E_Rj-_tZMYumYaet_aZbOh48Ia3Gks5t86FxgaJpZM4UpczP .

stieglma commented 6 years ago

I think so, It's the first step (normal checkout in jenkins pipeline with PreBuildMerge set).

Here is the full pipeline, perhaps this helps:

pipeline {
  agent none

  options {
    gitlabBuilds(builds: ['00 Pipeline Started', '10 Checkout and Merge Branches', '20 Clean Project', '30 Build & Code Metrics', '40 Collect Metrics', '50 Add merge request comments'])
    gitLabConnection('###')
  }

  stages {
    stage('Pipeline Started') {
      agent { label 'pipeline-starting-agent'}
      steps {
        gitlabCommitStatus(name: '00 Pipeline Started') {
          script {
            echo "Dummy step for starting the pipeline and prevent could not connect to CI messages"
          }
        }
      }
    }

    stage('Pipeline Execution') {
      agent { label 'worker' }
      steps {
        gitlabCommitStatus(name: '10 Checkout and Merge Branches') {
          script {
            echo "Checkout for Merge Request: ${env.gitlabMergeRequestTitle}"
            echo "source branch: ${env.gitlabSourceBranch}"
            echo "target branch: ${env.gitlabTargetBranch}"
            script {
              currentBuild.displayName = currentBuild.displayName + ":  ${env.gitlabMergeRequestTitle}"
              currentBuild.description = "Triggered by <a href=\"###/merge_requests/${env.gitlabMergeRequestIid}\">GitLab Merge Request ${env.gitlabMergeRequestIid}</a> (${env.gitlabMergeRequestTitle})"
            }
            checkout changelog: true,
                     poll: true,
                     scm: [$class: 'GitSCM',
                           branches: [[name: "origin/${env.gitlabSourceBranch}"]],
                     doGenerateSubmoduleConfigurations: false,
                     extensions: [[$class: 'PreBuildMerge',
                                  options: [fastForwardMode: 'FF',
                                            mergeRemote: 'origin',
                                            mergeTarget: "${env.gitlabTargetBranch}"]],
                                  [$class: 'UserIdentity',
                                   email: "${env.gitlabUserEmail}",
                                   name: "${env.gitlabUserName}"],
                                  [$class: 'CleanBeforeCheckout']],
                    submoduleCfg: [],
                    userRemoteConfigs: [[credentialsId: 'id',
                                         url: '###']]]
          }
        }

        gitlabCommitStatus(name : '20 Clean Project') {
          sh 'mvn clean'
        }

        gitlabCommitStatus(name : '30 Build & Code Metrics') {
          // findbugs and tasks are handled separately (in the post collect metrics step) so we disable them here
          withMaven(options: [findbugsPublisher(disabled: true),
                              openTasksPublisher(disabled: true),
                              junitPublisher(ignoreAttachments: true),
                              artifactsPublisher(disabled: true)]) {
              sh 'mvn verify -DskipTests -Dfindbugs.breakBuildOnError=false --fail-never | perl -pe \'END { exit $status } $status=1 if /BUILD FAILURE/;\''
          }
        }
      }

      post {
        always {
          gitlabCommitStatus(name : '40 Collect Metrics') {
            script {
              def common = load(".jenkins/jenkins_common.groovy")
              common.collectMetrics()
            }

            ViolationsToGitLab([apiToken: '',
                                apiTokenCredentialsId: 'id',
                                apiTokenPrivate: true,
                                authMethodHeader: true,
                                gitLabUrl: '',
                                ignoreCertificateErrors: true,
                                keepOldComments: false,
                                mergeRequestIid: env.gitlabMergeRequestIid,
                                projectId: "211",
                                shouldSetWip: true,
                                commentOnlyChangedContent: false,
                                violationConfigs: [[parser: 'FINDBUGS', pattern: '.*/target/findbugsXml\\.xml$', reporter: 'Findbugs']]])
          }
        }
      }
    }
  }

  post {
    always {
      gitlabCommitStatus(name : "50 Add merge request comments") {

        script {
          def resultIcon = currentBuild.result == 'SUCCESS' ? ':white_check_mark:' : ':anguished:'
          addGitLabMRComment comment: "$resultIcon Jenkins Build $currentBuild.result\n\nResults available at: [Jenkins [$env.JOB_NAME#$env.BUILD_NUMBER]]($env.BUILD_URL)"

          if (currentBuild.result == 'UNSTABLE') {
              updateGitlabCommitStatus name : "40 Collect Metrics", state: 'failed'
          }
        }
      }
    }
  }
}
tomasbjerre commented 6 years ago

And there are violations in the changed files? If you look in the findbugs xml report.

Den fre 15 juni 2018 14:15Thomas Stieglmaier notifications@github.com skrev:

I think so, It's the first step (normal checkout in jenkins pipeline with PreBuildMerge set).

Here is the full pipeline, perhaps this helps:

pipeline { agent none

options { gitlabBuilds(builds: ['00 Pipeline Started', '10 Checkout and Merge Branches', '20 Clean Project', '30 Build & Code Metrics', '40 Collect Metrics', '50 Add merge request comments']) gitLabConnection('###') }

stages { stage('Pipeline Started') { agent { label 'pipeline-starting-agent'} steps { gitlabCommitStatus(name: '00 Pipeline Started') { script { echo "Dummy step for starting the pipeline and prevent could not connect to CI messages" } } } }

stage('Pipeline Execution') {
  agent { label 'worker' }
  steps {
    gitlabCommitStatus(name: '10 Checkout and Merge Branches') {
      script {
        echo "Checkout for Merge Request: ${env.gitlabMergeRequestTitle}"
        echo "source branch: ${env.gitlabSourceBranch}"
        echo "target branch: ${env.gitlabTargetBranch}"
        script {
          currentBuild.displayName = currentBuild.displayName + ":  ${env.gitlabMergeRequestTitle}"
          currentBuild.description = "Triggered by <a href=\"###/merge_requests/${env.gitlabMergeRequestIid}\">GitLab Merge Request ${env.gitlabMergeRequestIid}</a> (${env.gitlabMergeRequestTitle})"
        }
        checkout changelog: true,
                 poll: true,
                 scm: [$class: 'GitSCM',
                       branches: [[name: "origin/${env.gitlabSourceBranch}"]],
                 doGenerateSubmoduleConfigurations: false,
                 extensions: [[$class: 'PreBuildMerge',
                              options: [fastForwardMode: 'FF',
                                        mergeRemote: 'origin',
                                        mergeTarget: "${env.gitlabTargetBranch}"]],
                              [$class: 'UserIdentity',
                               email: "${env.gitlabUserEmail}",
                               name: "${env.gitlabUserName}"],
                              [$class: 'CleanBeforeCheckout']],
                submoduleCfg: [],
                userRemoteConfigs: [[credentialsId: 'id',
                                     url: '###']]]
      }
    }

    gitlabCommitStatus(name : '20 Clean Project') {
      sh 'mvn clean'
    }

    gitlabCommitStatus(name : '30 Build & Code Metrics') {
      // findbugs and tasks are handled separately (in the post collect metrics step) so we disable them here
      withMaven(options: [findbugsPublisher(disabled: true),
                          openTasksPublisher(disabled: true),
                          junitPublisher(ignoreAttachments: true),
                          artifactsPublisher(disabled: true)]) {
          sh 'mvn verify -DskipTests -Dfindbugs.breakBuildOnError=false --fail-never | perl -pe \'END { exit $status } $status=1 if /BUILD FAILURE/;\''
      }
    }
  }

  post {
    always {
      gitlabCommitStatus(name : '40 Collect Metrics') {
        script {
          def common = load(".jenkins/jenkins_common.groovy")
          common.collectMetrics()
        }

        ViolationsToGitLab([apiToken: '',
                            apiTokenCredentialsId: 'id',
                            apiTokenPrivate: true,
                            authMethodHeader: true,
                            gitLabUrl: '',
                            ignoreCertificateErrors: true,
                            keepOldComments: false,
                            mergeRequestIid: env.gitlabMergeRequestIid,
                            projectId: "211",
                            shouldSetWip: true,
                            commentOnlyChangedContent: false,
                            violationConfigs: [[parser: 'FINDBUGS', pattern: '.*/target/findbugsXml\\.xml$', reporter: 'Findbugs']]])
      }
    }
  }
}

}

post { always { gitlabCommitStatus(name : "50 Add merge request comments") {

    script {
      def resultIcon = currentBuild.result == 'SUCCESS' ? ':white_check_mark:' : ':anguished:'
      addGitLabMRComment comment: "$resultIcon Jenkins Build $currentBuild.result\n\nResults available at: [Jenkins [$env.JOB_NAME#$env.BUILD_NUMBER]]($env.BUILD_URL)"

      if (currentBuild.result == 'UNSTABLE') {
          updateGitlabCommitStatus name : "40 Collect Metrics", state: 'failed'
      }
    }
  }
}

} }

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jenkinsci/violation-comments-to-gitlab-plugin/issues/16#issuecomment-397602752, or mute the thread https://github.com/notifications/unsubscribe-auth/AAa1Ex0GmhAqgjtIPO5qb3tnhpIhgyHrks5t86V2gaJpZM4UpczP .

stieglma commented 6 years ago

Yes, I explicitly added these to trigger the comments (to test if it works). They are also published in Jenkins itself, however not in gitlab. Did a double check of the respective files on the worker where I execute the tests, and the findbugsXml.xml contains 2 errors

tomasbjerre commented 6 years ago

And just to be clear. Those 2 errors are on files that you have changed in the source branch?

stieglma commented 6 years ago

yes, the merge request, which triggers this build was solely created for that purpose

tomasbjerre commented 6 years ago

change createCommentWithAllSingleFileComments to true

stieglma commented 6 years ago

that worked, now I have the overall comment, and the WIP setting. However the single comments are still not there, do I have to enable them separately?

tomasbjerre commented 6 years ago

Not possible. See https://github.com/jenkinsci/violation-comments-to-gitlab-plugin/issues/1

stieglma commented 6 years ago

seems to be merged cf. https://gitlab.com/gitlab-org/gitlab-ce/issues/20901

Thanks for your help anyway!