Best way for CI/CD in Jenkins with Nx

Viewed 1106

I have some questions about best practices in Nx Workspace and a big issue.

I want to move all my projects into a Nx workspace because I've got many shared libs.

Which will lead to only have one bitbucket repository for multiple apps and only one jenkins pipeline. (My jenkins pipeline is linting, checking, building and deploying my app on a AWS server.)

First: what is the best option for this job? As many articles and Nrwl documentation say: I can use the command nx affected to only build, deploy apps that are affected with my changes.

However that is leading to this error in jenkins console

fatal: Not a valid object name master
fatal: No such ref: 'master'
nx affected

I've try with

npx nx affected --target=test --base=master
npx nx affected --target=test --base=origin/master
npx nx affected --target=test --base=remote/origin/master

but none of them are working. Jenkins cannot find the master branch.

How do you do this process?

Second: If I decided to deploy in production, all my apps will be deployed and all my apps will have the same version number (there is only one package.json).

2 Answers

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
Related