Bitbucket Pipeline 失败,表示该步骤为空、为空或丢失

Jua*_*blo 8 bitbucket bitbucket-pipelines

我正在尝试配置一个 Bitbucket 管道来执行 SonarQube 管道,但 Bitbucket 抱怨管道步骤为空、为空或丢失。

我已将 SONAR_TOKEN 定义为具有正确令牌的项目变量。

这是我当前的 bitbucket-pipeline.yml 文件:

image: atlassian/default-image:2

clone:
  depth: full

definitions:
  caches:
    sonar: ~/.sonar/cache
  steps:
    - step: &sonarcloud
      name: Analyze on SonarCloud
      caches:
        - sonar
      script:
        - pipe: sonarsource/sonarcloud-scan:0.1.5
          variables:
            SONAR_TOKEN: ${SONAR_TOKEN}

pipelines:
  branches:
    '*':
      - step: *sonarcloud
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

Jua*_*blo 15

发现问题。

问题在于定义区域中的步骤详细信息缩进不正确,并且缺少一个额外的缩进级别。

代替:

...
- steps: &sonarcloud
  name: ...
  ...
Run Code Online (Sandbox Code Playgroud)

它是

...
- steps: &sonarcloud
    name: ... // Notice the extra level of indentation
    ...
Run Code Online (Sandbox Code Playgroud)

正确的 YAML 是:

image: atlassian/default-image:2

clone:
  depth: full

definitions:
  caches:
    sonar: ~/.sonar/cache
  steps:
    - step: &sonarcloud
        name: Analyze on SonarCloud
        caches:
          - sonar
        script:
          - pipe: sonarsource/sonarcloud-scan:0.1.5
            variables:
              SONAR_TOKEN: ${SONAR_TOKEN}

pipelines:
  branches:
    '*':
      - step: *sonarcloud
Run Code Online (Sandbox Code Playgroud)