Codefresh 标记管道

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

我有一个 codefresh 管道,在 Codefresh 使用的 YAML 格式化 Linter 中似乎出现了周期性错误。不过,在我打开支持票之前,我希望社区检查我的逻辑,因为也许我在这里遗漏了一些东西。

这是我的管道:

version: "1.0"
stages:
  - "clone"
  - "bump_version"
  - "push_tag"

steps:
  clone_repo:
    title: "Cloning repository"
    type: "git-clone"
    repo: "${{CF_REPO_NAME}}"
    revision: "${{CF_BRANCH}}"
    stage: "clone"

  detect_last_tag:
    title: "Detecting last tag"
    type: "freestyle"
    image: "alpine/git"
    stage: "bump_version"
    commands:
      - |
        LAST_TAG=$(git describe --tags --abbrev=0 || echo '0.0.0')
        echo "LAST_TAG=\"$LAST_TAG\"" > /codefresh/volume/env_vars_to_export/env_vars
    volumes:
      - name: env_vars_to_export
        path: /codefresh/volume/env_vars_to_export

  determine_new_version:
    title: "Determining new version"
    type: "freestyle"
    image: "alpine/git"
    stage: "bump_version"
    commands:
      - |
        source /codefresh/volume/env_vars_to_export/env_vars
        echo "Last tag is $LAST_TAG"

        # Extract version components
        MAJOR=$(echo "$LAST_TAG" | cut -d. -f1)
        MINOR=$(echo "$LAST_TAG" | cut -d. -f2)
        PATCH=$(echo "$LAST_TAG" | cut -d. -f3)

        # Convert to strings explicitly
        MAJOR="${MAJOR}"
        MINOR="${MINOR}"
        PATCH="${PATCH}"
        echo "MAJOR: \"$MAJOR\", MINOR: \"$MINOR\", PATCH: \"$PATCH\""

        # Determine the new version based on PR description
        if echo "$CF_PULL_REQUEST_DESCRIPTION" | grep -q "#major"; then
          MAJOR=$((MAJOR + 1))
          MAJOR="${MAJOR}"
          MINOR="0"
          PATCH="0"
        elif echo "$CF_PULL_REQUEST_DESCRIPTION" | grep -q "#minor"; then
          MINOR=$((MINOR + 1))
          MINOR="${MINOR}"
          PATCH="0"
        else
          PATCH=$((PATCH + 1))
          PATCH="${PATCH}"
        fi

        NEW_TAG="${MAJOR}.${MINOR}.${PATCH}"
        echo "NEW_TAG=\"$NEW_TAG\"" > /codefresh/volume/env_vars_to_export/env_vars
    volumes:
      - name: env_vars_to_export
        path: /codefresh/volume/env_vars_to_export

  push_tag:
    title: "Pushing new tag"
    type: "freestyle"
    image: "alpine/git"
    stage: "push_tag"
    commands:
      - |
        source /codefresh/volume/env_vars_to_export/env_vars
        echo "Tagging with NEW_TAG: \"$NEW_TAG\""
        git tag "$NEW_TAG"
        git push origin "$NEW_TAG"
    volumes:
      - name: env_vars_to_export
        path: /codefresh/volume/env_vars_to_export

我遇到的错误是:

LINE 15
"0" must be a string. Current value: [object Object]
LEARN MORE
Please make sure you have all the required fields and valid values

LINE 28
"0" must be a string. Current value: [object Object]
LEARN MORE
Please make sure you have all the required fields and valid values

LINE 70
"0" must be a string. Current value: [object Object]
LEARN MORE
Please make sure you have all the required fields and valid values

管道应该标记事物,如果没有找到标记,则用

0.0.0
标记。但 Codefresh 似乎不喜欢我的管道。我是否没有正确插入零?

yaml codefresh yamllint
1个回答
0
投票

显然 Codefresh 验证器在指定

volumes
时失败:

version: '1.0'
stages:
  - "clone"
  - "bump_version"
  - "push_tag"

steps:
  clone_repo:
    title: "Cloning repository"
    type: "git-clone"
    repo: "${{CF_REPO_NAME}}"
    revision: "${{CF_BRANCH}}"
    stage: "clone"

  detect_last_tag:
    title: "Detecting last tag"
    type: "freestyle"
    image: "alpine/git"
    stage: "bump_version"
    commands:
      - |
        # Fetch the latest tag or default to "0.0.0"
        LAST_TAG=$(git describe --tags --abbrev=0 || echo "0.0.0")
        echo "Last tag detected: $LAST_TAG"
        # Write the LAST_TAG to a specific file within the volume
        echo "LAST_TAG=$LAST_TAG" > /codefresh/volume/env_vars_to_export/env_vars

  determine_new_version:
    title: "Determining new version"
    type: "freestyle"
    image: "alpine/git"
    stage: "bump_version"
    commands:
      - |
        # Source the environment variables from the specific file
        source /codefresh/volume/env_vars_to_export/env_vars
        echo "Last tag is $LAST_TAG"

        # Extract version components
        IFS='.' read -r -a VERSION <<< "$LAST_TAG"
        MAJOR="${VERSION[0]}"
        MINOR="${VERSION[1]}"
        PATCH="${VERSION[2]}"

        echo "Detected PR message: $CF_PULL_REQUEST_DESCRIPTION"

        # Determine the new version based on PR description
        if echo "$CF_PULL_REQUEST_DESCRIPTION" | grep -q "#major"; then
          MAJOR=$((MAJOR + 1))
          MINOR=0
          PATCH=0
        elif echo "$CF_PULL_REQUEST_DESCRIPTION" | grep -q "#minor"; then
          MINOR=$((MINOR + 1))
          PATCH=0
        else
          PATCH=$((PATCH + 1))
        fi

        NEW_TAG="${MAJOR}.${MINOR}.${PATCH}"
        echo "New tag: $NEW_TAG"
        # Write the NEW_TAG to the same environment variables file
        echo "NEW_TAG=$NEW_TAG" > /codefresh/volume/env_vars_to_export/env_vars

  tag_and_push:
    title: "Tagging and pushing to repository"
    type: "freestyle"
    image: "alpine/git"
    stage: "push_tag"
    commands:
      - |
        # Source the environment variables
        source /codefresh/volume/env_vars_to_export/env_vars
        echo "Tagging with NEW_TAG: \"$NEW_TAG\""
        # Create and push the new tag
        git tag "$NEW_TAG"
        git push origin "$NEW_TAG"

通过了验证,管道是否有效则是另一回事。

但我被告知 Codefresh 支持删除以下内容:

volumes:
    - name: env_vars_to_export
      path: /codefresh/volume/env_vars_to_export

这似乎有效并通过了用户界面中的验证。

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