question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`affected:build` failing in the pipeline

See original GitHub issue

Current Behavior

The affected:build is failing with the message:

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

Although, the git fetch is being called and branches are existing at the time the command is called

Successfully extracted cache
Executing "step_script" stage of the job script 00:02
$ git fetch
From https://some-path
 * [new branch]      add-linting-pipeline -> origin/add-linting-pipeline
 * [new branch]      master               -> origin/master
 * ...
$ NODE_ENV=production nx affected:build --parallel --maxParallel=8 --configuration=dev --deployUrl=./
>  NX   NOTE  Affected criteria defaulted to --base=master --head=HEAD
fatal: Not a valid object name master
fatal: No such ref: 'master'
nx affected:build
Build applications and publishable libraries affected by changes
Run command using --base=[SHA1] (affected by the committed, uncommitted and
untracked changes):
  --base  Base of the current branch (usually master)                   [string]
or using --base=[SHA1] --head=[SHA2] (affected by the committed changes):
  --base  Base of the current branch (usually master)                   [string]
  --head  Latest commit of the current branch (usually HEAD)            [string]
or using:
  --files        Change the way Nx is calculating the affected command by
                 providing directly changed files, list of files delimited by
                 commas                                                  [array]
  --uncommitted  Uncommitted changes                                   [boolean]
  --untracked    Untracked changes                                     [boolean]
Options:
  --help           Show help                                           [boolean]
  --version        Show version number                                 [boolean]
  --parallel       Parallelize the command (default: false)            [boolean]
  --maxParallel    Max number of parallel processes. This flag is ignored if the
                   parallel option is set to `false`. (default: 3)      [number]
  --all            All projects                                        [boolean]
  --exclude        Exclude certain projects from being processed
                                                           [array] [default: []]
  --runner         This is the name of the tasks runner configured in nx.json
                                                                        [string]
  --skip-nx-cache  Rerun the tasks even when the results are available in the
                   cache                              [boolean] [default: false]
  --configuration  This is the configuration to use when performing tasks on
                   projects                                             [string]
  --only-failed    Isolate projects which previously failed
                                                      [boolean] [default: false]
  --verbose        Print additional error stack trace on failure
Error: Command failed: git merge-base --fork-point "master" "HEAD"
fatal: No such ref: 'master'
    at checkExecSyncError (child_process.js:616:11)
    at Object.execSync (child_process.js:652:15)
    at getFilesUsingBaseAndHead (/builds/fo7brMD7/1/.../node_modules/@nrwl/workspace/src/command-line/shared.js:55:37)
    at Object.parseFiles (/builds/fo7brMD7/1/.../node_modules/@nrwl/workspace/src/command-line/shared.js:31:20)
    at projectsToRun (/builds/fo7brMD7/1/.../node_modules/@nrwl/workspace/src/command-line/affected.js:97:108)
    at Object.<anonymous> (/builds/fo7brMD7/1/.../node_modules/@nrwl/workspace/src/command-line/affected.js:27:26)
    at Generator.next (<anonymous>)
    at fulfilled (/builds/fo7brMD7/1/.../node_modules/@nrwl/workspace/node_modules/tslib/tslib.js:114:62) {
  status: 128,
  signal: null,
  output: [
    null,
    <Buffer >,
    <Buffer 66 61 74 61 6c 3a 20 4e 6f 20 73 75 63 68 20 72 65 66 3a 20 27 6d 61 73 74 65 72 27 0a>
  ],
  pid: 36,
  stdout: <Buffer >,
  stderr: <Buffer 66 61 74 61 6c 3a 20 4e 6f 20 73 75 63 68 20 72 65 66 3a 20 27 6d 61 73 74 65 72 27 0a>
}
Cleaning up file based variables 00:00
ERROR: Job failed: command terminated with exit code 1

Environment

Node : 14.15.4 OS : win32 x64 yarn : 2.4.2

nx : 11.1.1 @nrwl/angular : Not Found @nrwl/cli : 12.1.1 @nrwl/cypress : 12.1.1 @nrwl/devkit : 12.1.1 @nrwl/eslint-plugin-nx : 12.1.1 @nrwl/express : Not Found @nrwl/jest : 12.1.1 @nrwl/linter : 12.1.1 @nrwl/nest : Not Found @nrwl/next : Not Found @nrwl/node : Not Found @nrwl/react : 12.1.1 @nrwl/schematics : 8.12.11 @nrwl/tao : 12.1.1 @nrwl/web : 12.1.1 @nrwl/workspace : 12.1.1 @nrwl/storybook : 12.1.1 @nrwl/gatsby : Not Found typescript : 4.3.2

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:7

github_iconTop GitHub Comments

5reactions
Anenthcommented, Jul 15, 2021

These worked for me

  1. Add --base origin/master to nx affected:build
  2. Fetch all the branches with GitHub action by setting fetch-depth: 0
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
1reaction
erdyssoncommented, Oct 5, 2022

For the ones running into issue on Gitlab CI, two things to make it work;

First; set the git depth via UI to 0, under settings -> CI CD -> General pipelines -> git depth And second, add GIT_FETCH_EXTRA_FLAGS: --unshallow in .gitlab-ci.yml under variables

EDIT: GIT_FETCH_EXTRA_FLAGS: --unshallow worked only in the first run, for following runs runner throws error:

fatal: --unshallow on a complete repository does not make sense

The solution I found is setting the depth as 0, and passing --base=origin/master to affected command

Read more comments on GitHub >

github_iconTop Results From Across the Web

Identify and fix broken builds with CI/CD pipelines | TechTarget
Broken or failing builds in a CI/CD pipeline can deteriorate a team's faith in its own processes. It can also hinder a team's...
Read more >
Troubleshoot pipeline runs - Azure DevOps - Microsoft Learn
My pipeline is failing on a command-line step such as MSBUILD. It is helpful to narrow whether a build or release failure is...
Read more >
How to troubleshoot a GitLab pipeline failure
Sometimes builds fail because of a merge conflict. GitLab's merge trains exist to make sure that big problems don't get pushed onto the...
Read more >
Build Pipeline Failing - Visual Studio Feedback
Our build pipelines started failing today (unrelated to our code) but the task itself. We run a docker task on a microsoft hosted...
Read more >
Troubleshooting CodePipeline - AWS Documentation
Pipeline error: A Jenkins build or test action runs for a long time and then fails due to lack of credentials or permissions...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found