Tag Pipelines vs Cargo workspace publish command

⚓ Rust    📅 2026-05-08    👤 surdeus    👁️ 2      

surdeus

Hello, using the cargo ws crate, I understand to get it to run on anything other than master, you must pass in the flag --allow-branch <BRANCH-NAME>. I am trying to versoin and tag my crates to publish to a private registry in a gitlab tag pipeline, which is not pointing to a branch but a commit hash on main, essentially taking a screenshot of the source code at that point in time. I am trying to figure out how I can get it to run on the tag branches. It is incredibly important context that I am using Gitlab, which has a specific tag pipeline. I am currently getting this error for my publish-crate job:

 * tag               0.14.0     -> FETCH_HEAD
$ git checkout --detach "$CI_COMMIT_TAG"
HEAD is now at <commit> merge branch y into x
$ echo "Publishing crates for tag $CI_COMMIT_TAG"
Publishing crates for tag 0.14.0
$ cargo ws publish --yes --allow-branch '*'
error: not on a git branch
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1

And here is my template file for additional context:


stages:
  - package
  - release
  - lint
  - build
  - test

# note some of this is generic/anonymized
include:
  - component: rust component
    inputs:
      component-version-ref: my version ref
  - component: release component
    inputs:
      component-version-ref: my version ref

publish-crates:
  tags:
    - runner tag
  stage: release
  image:
    name: rust image
    entrypoint: ["entrypoint/"]
  rules:
    - if: $CI_COMMIT_TAG
    - when: never
  before_script:
    - git config --global --add safe.directory "$(pwd)"
    - git config user.name "$GITLAB_USER_NAME"
    - git config user.email "$GITLAB_USER_EMAIL"
    - git remote set-url origin "https://__token__:$TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH.git"
    - git remote set-url --push origin "https://__token__:$TOKEN@$CI_SERVER_HOST/$CI_PROJECT_PATH.git"
    - git fetch origin "refs/tags/$CI_COMMIT_TAG"
    - git checkout --detach "$CI_COMMIT_TAG"
  script:
    - echo "Publishing crates for tag $CI_COMMIT_TAG"
    - cargo ws publish --yes --allow-branch '*'

I understand this may not be the best place to ask this question since it is so specific to an individual crate I am using but I thought this may have been experienced by someone else and thought I would reach out anyway. Thanks!

3 posts - 2 participants

Read full topic

🏷️ Rust_feed