Git Product home page Git Product logo

Comments (12)

tomasbjerre avatar tomasbjerre commented on June 27, 2024

Do you have an example of where it does not work?

from violation-comments-to-stash-plugin.

testuser7 avatar testuser7 commented on June 27, 2024

For now I need to manually specify projectKey and repoSlug:

                if (env.CHANGE_ID) {
                    step([$class: 'ViolationsToBitbucketServerRecorder',
                          config: [useUsernamePasswordCredentials        : true,
                                   projectKey                            : 'prokey',
                                   repoSlug                              : 'repository-name',
                                   pullRequestId                         : env.CHANGE_ID,
                                   commentOnlyChangedContent             : false,
                                   commentOnlyChangedContentContext      : 0,
                                   createCommentWithAllSingleFileComments: false,
                                   createSingleFileComments              : true,
                                   violationConfigs                      : [[pattern : '.*/checkstyle-result\\.xml$',
                                                                             reporter: 'CHECKSTYLE']]]])
                }

Simplified configuration example:

                if (env.CHANGE_ID) {
                    step([$class: 'ViolationsToBitbucketServerRecorder',
                          config: [repositoryConfig                      : scm,
                                   pullRequestId                         : env.CHANGE_ID,
                                   commentOnlyChangedContent             : false,
                                   commentOnlyChangedContentContext      : 0,
                                   createCommentWithAllSingleFileComments: false,
                                   createSingleFileComments              : true,
                                   violationConfigs                      : [[pattern : '.*/checkstyle-result\\.xml$',
                                                                             reporter: 'CHECKSTYLE']]]])
                }

from violation-comments-to-stash-plugin.

tomasbjerre avatar tomasbjerre commented on June 27, 2024

Are you sure scm has these values? And if it does, cant you do something like this?

projectKey                            : env.repositoryConfig.projectKey,

from violation-comments-to-stash-plugin.

testuser7 avatar testuser7 commented on June 27, 2024

Yes, I can simply use: checkout scm to checkout repository.
Method scm.getKey() return full repository url.

There is no any environment variables containing project key or repository name.

from violation-comments-to-stash-plugin.

tomasbjerre avatar tomasbjerre commented on June 27, 2024

Perhaps if you use https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket and let it provide these variables for you? Then I think you can do:

projectKey                            : env.PULL_REQUEST_TO_REPO_PROJECT_KEY,

If you parameterize the job with a String parameter like PULL_REQUEST_TO_REPO_PROJECT_KEY

from violation-comments-to-stash-plugin.

testuser7 avatar testuser7 commented on June 27, 2024

Right now I'm using Bitbucket Branch Source Plugin with Post Webhooks for Bitbucket. Direct usage of scm variable will be most reasonable.

from violation-comments-to-stash-plugin.

tomasbjerre avatar tomasbjerre commented on June 27, 2024

Perhaps you can get the project key from getRepoOwner and repository from getRepository. But I'm just guessing here =)

from violation-comments-to-stash-plugin.

testuser7 avatar testuser7 commented on June 27, 2024

I'm not sure if I can access this methods from pipeline groovy script.

from violation-comments-to-stash-plugin.

jansohn avatar jansohn commented on June 27, 2024

I'd also appreciate this feature.

from violation-comments-to-stash-plugin.

jetersen avatar jetersen commented on June 27, 2024

Definitely possible to get the ID and even more: https://github.com/jenkinsci/office-365-connector-plugin/blob/53f1823060c4a7aba72294a08c0efba6751664d5/src/main/java/jenkins/plugins/office365connector/ActionableBuilder.java#L59-L89

Here you get the full URL so ya to the PR even
String urlString = oma.getObjectUrl();

from violation-comments-to-stash-plugin.

amandel avatar amandel commented on June 27, 2024

For me the following pipeline snipped could collect all needed data:

@NonCPS
void publishBuildResults() {
  try {
    def gitUrl = scmVars.GIT_URL_1
    // https://myserver.example.com/bitbucket/scm/SETOOLS/setools-sbs-bitbucket.git
    def urlMatcher = gitUrl =~ '^(https?://[^/]*/bitbucket)/scm/([^/]*)/([^/]*).git$'
    if (urlMatcher) {
      def bitbucketServer = urlMatcher[0][1]
      def projectKey = urlMatcher[0][2]
      def repoSlug = urlMatcher[0][3]
      def changeId = pipeline.env.CHANGE_ID;
      def credentialIdTemp = pipeline.scm.getUserRemoteConfigs()[0].credentialsId;
      pipeline.ViolationsToBitbucketServer([
          bitbucketServerUrl                    : bitbucketServer,
          commentOnlyChangedContent             : true,
          commentOnlyChangedContentContext      : 5,
          createCommentWithAllSingleFileComments: false,
          createSingleFileComments              : true,
          maxNumberOfViolations                 : 99999,
          keepOldComments                       : true,
          projectKey                            : projectKey,
          pullRequestId                         : changeId,
          repoSlug                              : repoSlug,
          credentialsId                         : credentialIdTemp,
          commentTemplate                       : """
**{{violation.severity}}**: {{violation.message}}
*Reporter: {{violation.reporter}}{{#violation.rule}} //  Rule: {{violation.rule}}{{/violation.rule}}*
""",
          violationConfigs            : [
              // Many more formats available, check https://github.com/tomasbjerre/violations-lib
              [parser: 'SONAR', pattern: '.*/target/sonar/sonar-report.json', reporter: 'SONAR']
          ]
      ])
    } else {
      pipeline.echo("Does not look like a bitbucket server - think about migrating?")
    }
  } catch (error) {
    // do not leak errors but report them.
    pipeline.echo("Error during result publish: " + error)
  }
}

from violation-comments-to-stash-plugin.

robross0606 avatar robross0606 commented on June 27, 2024

From what I can tell, this is really more the fault of Bitbucket Branch Source Plugin because it doesn't expose the Bitbucket JSON payload data (project, slug, etc.) from the webhook trigger into the pipeline.

from violation-comments-to-stash-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.