nx: Jenkins CI - npx nx affected --target=build throws as error

Expected Behavior

Build should execute on Jenkins with same source as executes on local environment

Current Behavior

Source checked into git, Jenkins multi branch pipeline executes

Build stage fails with error:

  • npx nx affected --target=build – master HEAD fatal: Not a valid object name affected Command failed: git merge-base affected master fatal: Not a valid object name affected

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. Source repo available at https://git.symbiotics.co.za/mike.love/NXPoC.git
  2. Checkout locally, build via npm install & npm run build => successful nx build
  3. Run as Jenkinsmulti pipeline build

Context

Please provide any relevant information about your setup:

  • version of Nx used (Please run nx report at the root of your workspace and copy the results here if you are using Nx 8.6.1 or greater)
  • 3rd-party libraries and their versions
  • and most importantly - a use-case that fails

A minimal reproduction scenario allows us to quickly confirm a bug (or point out coding problem) as well as confirm that we are fixing the right problem.

Failure Logs

Extract of log file included below:

[Pipeline] } [Pipeline] // nodejs [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (Declarative: Post Actions) [Pipeline] archive The archive step is deprecated, please use archiveArtifacts instead. [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // timeout [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline ERROR: script returned exit code 1 Finished: FAILURE

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

I think this is worth to mention in the document.

@vsavkin ,

Just a suggestion, I had the same issue with jenkins where the origin develop was not fetched as jenkins was doing shadow cloning, I resolved the issue by enabling advanced clone option in multibranch pipline and enable fetch tags. It helped me. I hope it helps you. Screenshot 2021-03-25 at 23 24 56

Just for anyone else finding this thread. @SanthoshKumar-Prodapt fix worked for me … just make sure you use origin in your branch name. Originally I just used develop and it did not work.

Also I found it easier to add the command to my package.json and call that from jenkins.

    "test-affected-dev": "npm run affected:test -- --base=origin/develop --head=HEAD",
    "lint-affected-dev": "npm run affected:lint -- --base=origin/develop --head=HEAD",

Hello,

Does anyone succeded in using nx affected in a jenkins pipeline?