when executing nx affected --target=build in AWS CodeBuild using the --files argument i would expect the affected apps to be build. here is the command I am executing:
npm run affected -- --target=build --files=libs/svc-service-lane-ng-ui/src/lib/accept-quote-line-dialog/accept-quote-line-dialog.component.ts --prod
When I run this locally, it executes as I would expect. When I execute this via AWS CodeBuild the child process executing the command exits with code 0 immediately, with nothing in the stderr or stdout.
I've verified the path to the files passed to the --files argument is accurate. Even if they were not, I woudl expect some sort of output from the nx execution, but there is nothing in either stderr or stdout.
Please provide any relevant information about your setup:
Running version 8.5 of NX.
When happens when you run locally and in CI?
npm run affected:apps -- --files=libs/svc-service-lane-ng-ui/src/lib/accept-quote-line-dialog/accept-quote-line-dialog.component.ts
npm run affected:libs -- --files=libs/svc-service-lane-ng-ui/src/lib/accept-quote-line-dialog/accept-quote-line-dialog.component.ts
Also what happens if you run ng-build or nx build directly?
when running both those commands locally it behaves as I would expect. in CI it does not work in the same manner as stated above.
possibly worth noting that my CI process is calling a javascript file ("node ci.js") as I am doing a few things prior to trying to execute the affected build. I did try explicitly setting the build command in CI to "npm run affected:apps -- --files=libs/svc-service-lane-ng-ui/src/lib/accept-quote-line-dialog/accept-quote-line-dialog.component.ts" as well though, but returned the same result.
running "nx build" in CI also automatically exits with code 0 with nothing in the stderr or stdout.
@vsavkin Any suggestions on where to start figuring this one out? I know you're quite busy so I dont mind figuring it out..just need a little direction!
@jimdubbs really sorry for the late reply.
nx build simply delegates to the angular cli. It doesn't do much apart from that.
Do you see the same result when running ng build ...?
@vsavkin running ng build works as expected.
@vsavkin I ran nx g @nrwl/web:application app today and I noticed the same bahavior (exit 0 without any information in console.
My stack:
nx: 8.2.0
node: 10.16.0
npm: 6.9.0
os: Ubuntu 19.10
EDIT.
If I'll run through ng, command works correctly.
@kklimczak could you step through the nx script to see why it exists. This is the script is invoked when you run nx build: node_modules/@nrwl/cli/lib/init-local.js
in trying to figure out whats happening, if I import the affected.js directly from node_modules and use that everything works correctly.
Hi, sorry about this.
This was mislabeled as stale. We are testing ways to mark _not reproducible_ issues as stale so that we can focus on actionable items but our initial experiment was too broad and unintentionally labeled this issue as stale.
We are seeing this same issue in our CodeBuild jobs when running nx affected:build --base=origin/master --head=HEAD, nx affected:test --base=origin/master --head=HEAD, and even nx print-affected. All of these exit 0 printing nothing more than Done in 0.08s..
I have discovered a workaround. If I disable local caching for a build, nx behaves as expected. Obviously this is less than desirable so we'd love to get this solved soon.
I am happy to contribute a PR to resolve this, but I need a little direction here as I am completely baffled by this behavior.
@imaustink quick question.
Folks. I need more information about the issue. @imaustink could you help by answering the questions above?
We are facing the same issue using AWS Amplify console
we release a new version only if the test and e2e test passed successfully, but the script fails and the AWS Amplify console just got an exit code 0
amplify.yml
test:
phases:
preTest:
commands:
- nvm use $VERSION_NODE_12
test:
commands:
- echo "Run unit and e2e tests based on Nx dep-graph"
- ./run-dep-graph.sh
- exitCode=$?
- if [ ${exitCode} -ne 0 ]; then exit 1; fi
- echo "Publish new version"
- if [ "${AWS_BRANCH}" = "master" ]; then npx semantic-release; fi
postTest:
commands:
- echo "Generate Mochawesome reports"
- ./generate-reports.sh
run-dep-graph.sh
#!/usr/bin/env bash
set -Eeuxo pipefail
REVISION=origin/${AWS_BRANCH}~1
AWS_BRANCH=master
npm run affected:test -- --base=${REVISION} --head=${AWS_BRANCH} --parallel
exitCode=$?
if [ ${exitCode} -ne 0 ]; then exit 1; fi
exit 0;
As you can see in the image below one of our test fails and it is notifies as INFO instead of an ERROR
[INFO]: > nx run utils:test
In the image below you can see the AWS Amplify Console log for each statement and the exit code was 0

This is a failing test

This is a failing e2e
If we run the same script locally it break the bash execution and exit with a error code 1

The expected behavior for this bash script on any environment CI or local with a failing test
REVISION=origin/${AWS_BRANCH}~1
AWS_BRANCH=master
npx nx affected:test --base=${REVISION} --head=${AWS_BRANCH} --parallel
exitCode=$?
echo "exitCode = $?"
if [ ${exitCode} -ne 0 ]; then exit 1; fi
exit 0;
the affected completes with an exit code different than 0
then the exitCode=$? get that value and continues the script execution
Currently it just fails and break the execution, so we are unable to add custom handling
@imaustink quick question.
- When you run print-affected, there is nothing being displayed?
Correct- If you disable caching for a build, what happens to print-affected?
With caching disabled,print-affected(and seemingly all other NX commands) works as expected, meaning it prints out a JSON object of the projects, libs, and dependencies that changed.
Thank you folks.
This is the place were we exit with status code 1: https://github.com/nrwl/nx/blob/master/packages/workspace/src/tasks-runner/run-command.ts#L84
Because you see the failures printed out, I expect the hasFailure function to return "true".
You can verify it that it's called by adding a console.log statement there in a postinstall script:
fs.writeFileSync("node_modules/@nrwl/workspace/src/tasks-runner/run-command.js"",
fs.readFileSync("node_modules/@nrwl/workspace/src/tasks-runner/run-command.js").toString().replace("process.exit(1);", "console.log('exit1!!!!');process.exit(1);")
Let me know if you see exit1!!! printed out. And please try either latest 9x or latest 10x.
@vsavkin the problem is that the nx CLI is exiting with a code 0 without seemingly doing anything. It is not exiting with code 1. Looks like @jcvalerio was also seeing it exit with code 0 in CI, but when he ran it locally when he got a code 1. I believe that is unrelated to this issue.
Exactly @imaustink !!
@vsavkin, I tried to describe what happens locally and on the CI, and the results are totally different.
I know that the behavior is different. The CI output in the screenshot is printed right before the line I highlighted. So I image the printResults is called, but process.exit(1) is either not called, or it is called and some other process wraps your command and ignore status code 1. So I'm curious which one is it.
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 馃檹