問題描述
使用 Nx 在 Jenkins 中進行 CI/CD 的最佳方式 (Best way for CI/CD in Jenkins with Nx)
我對 Nx Workspace 中的最佳實踐有一些疑問和一個大問題。
我想將我的所有項目移到 Nx 工作區,因為我有很多共享庫。
這將導致多個應用程序只有一個 bitbucket 存儲庫和一個 jenkins 管道。(我的 jenkins 管道正在 AWS 服務器上檢查、檢查、構建和部署我的應用程序。)
首先:什麼是這項工作的最佳選擇?正如許多文章和 Nrwl 文檔所說:我可以使用命令 nx affected 僅構建、部署受我的更改影響的應用程序。
但是這會導致這個錯誤jenkins 控制台
fatal: Not a valid object name master
fatal: No such ref: 'master'
nx affected
我嘗試過
npx nx affected ‑‑target=test ‑‑base=master
npx nx affected ‑‑target=test ‑‑base=origin/master
npx nx affected ‑‑target=test ‑‑base=remote/origin/master
但它們都沒有工作。
參考解法
方法 1:
You may want to reference ‑‑base=HEAD~1
as this documentation suggests: https://nx.dev/l/r/ci/monorepo‑ci‑jenkins
This happened to work for our CICD dev and hope it help you!
方法 2:
I had same issue. Fetching needed for comparison branch before running commands helped:
git fetch origin master:refs/remotes/origin/master
npx nx affected ‑‑target=test ‑‑base=origin/master
(by achtlos、jonnie、someone_new)