最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

git - How to Automatically run npm version patch in GitLab CICD - Stack Overflow

programmeradmin5浏览0评论

I have an Angular monorepo containing one application and three libraries. I am trying to automate versioning and publishing for each library using GitLab CI/CD.

Issue 1 (Local behavior): When I run the following command from the root directory of the monorepo:

npm version patch

The version number is updated. A commit is automatically created and pushed. However, when I navigate into a library folder (where its package.json exists) and run the same command:

cd projects/my-library  
npm version patch 

The version number is updated in the package.json. But the changes are not committed or pushed automatically.

Question: Why does npm version patch work as expected in the root directory but not inside the library folder?

Issue 2 (Pipeline behavior): I am running the following script inside my GitLab CI/CD pipeline:

image: node:lts
    
stages:
  - publish

.publish_npm_template:
  stage: publish
  script:
    - |
      cd "${CI_PROJECT_DIR}"
      echo "Git user email: $GITLAB_USER_EMAIL"
      echo "Git user login: $GITLAB_USER_LOGIN"
      git config --global user.email "$GITLAB_USER_EMAIL"
      git config --global user.name "$GITLAB_USER_LOGIN"
      
      echo "Fetching latest changes..."
      git fetch origin $CI_COMMIT_REF_NAME
      
      echo "Checking out the current branch..."
      git switch $CI_COMMIT_REF_NAME
      
      echo "Running npm version patch..."
      npm version patch

publish_npm_Library:
  extends: .publish_npm_template
  variables:
    LIBRARY_DIRECTORY: shared



However, the new version is not pushed to the branch, regardless of whether I run the script from the root directory or inside a library folder.

Question:

Why is the version update not being pushed when running inside GitLab CI/CD?

How can I ensure that npm version patch commits and pushes changes correctly in the pipeline?

发布评论

评论列表(0)

  1. 暂无评论