没有使用aws codebuild获取有关Bitbucket拉取请求的Sonar注释

问题描述 投票:0回答:1

嗨,我正在使用带有声纳的aws代码构建来进行位桶提取请求装饰。...但是我没有收到关于提取请求的任何注释。...

aws codebuild日志...。

[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个回答
0
投票

只需在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

© www.soinside.com 2019 - 2024. All rights reserved.