【问题标题】:Not getting Sonar comments on bitbucket pull request using aws codebuild使用 aws codebuild 未收到有关 bitbucket 拉取请求的 Sonar 评论
【发布时间】:2020-04-21 03:55:33
【问题描述】:

您好,我正在使用带有声纳的 aws 代码构建来进行 bitbucket 拉取请求装饰......但我没有收到任何关于拉取请求的 cmets....

aws 代码构建日志....

[sonar4bitbucket] No open pull requests with source branch '' found. No analysis will be performed. ....

这是我的 aws 代码构建命令 ....

sonar-scanner  -Dsonar.branch=$GIT_BRANCH -Dsonar.bitbucket.branchName=$GIT_BRANCH -Dsonar.analysis.mode=issues -Dsonar.bitbucket.oauthClientSecret=secret -Dsonar.bitbucket.oauthClientKey=key -Dsonar.bitbucket.minSeverity=INFO -Dsonar.host.url=my server-url -Dsonar.bitbucket.teamName=teamname -Dsonar.bitbucket.repoSlug=myreponame -Dsonar.bitbucket.accountName=my-account-name -Dsonar.bitbucket.approvalFeatureEnabled=false -Dsonar.bitbucket.buildStatusEnabled=true 

我认为问题在于这两个属性,即-Dsonar.branch=$GIT_BRANCH -Dsonar.bitbucket.branchName=$GIT_BRANCH,但我不知道如何从 aws 代码构建环境变量中获取这些属性的值

(https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html)

【问题讨论】:

    标签: amazon-web-services bitbucket sonarqube-scan aws-codebuild


    【解决方案1】:

    只需在 buildspec 中运行此命令即可推断分支名称:

    version: 0.2
    phases:
      build:
        commands:
          - MY_BRANCH_NAME=$(git for-each-ref --format='%(objectname) %(refname:short)' refs/heads | awk "/^$(git rev-parse HEAD)/ {print \$2}")
          - echo $MY_BRANCH_NAME
    

    输出类似于:

    [Container] 2020/01/03 10:41:04 Running command MY_BRANCH_NAME=$(git for-each-ref --format='%(objectname) %(refname:short)' refs/heads | awk "/^$(git rev-parse HEAD)/ {print \$2}") 
    
    [Container] 2020/01/03 10:41:04 Running command echo $MY_BRANCH_NAME 
    master
    

    感谢@cascabal 的回答:How to find the current git branch in detached HEAD state

    【讨论】:

    猜你喜欢
    • 2020-01-05
    • 2018-10-23
    • 2019-09-06
    • 2019-11-26
    • 1970-01-01
    • 2019-12-19
    • 2019-10-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多