I found that the exit code is a semi-generic code that seems to be related to a warning that the system created as it was running the code associated to my login credentials.  I changed a code file to point to a system account and it worked fine.  Seems like the SSH element related to Bamboo failing due to this warning.  Some reference material that suggests that the exit code is related to code failure would be useful, but I also understand that Bamboo isn't designed to interpret return codes for every software package that it services.   So if you're using Bamboo to build and deploy SAS code, and you are getting this exit code, I'd suggest scanning the SAS logs for any warning messages - even if they don't specifically appear to be related to your committed code. Answer from Doug Gordon on community.atlassian.com
🌐
GitHub
github.com β€Ί yarnpkg β€Ί yarn β€Ί issues β€Ί 8467
What does "error Command failed with exit code 2"mean? Β· Issue #8467 Β· yarnpkg/yarn
November 19, 2020 - run command: yarn build There are no error logs, but some warning, and the following log at the end: error Command failed with exit code 2. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. The document...
Author Β  lovi-cn
🌐
Stack Overflow
stackoverflow.com β€Ί questions β€Ί 44667930 β€Ί flow-error-command-failed-with-exit-code-2
Flow : Error Command failed with exit code 2
Did you forget to declare type parameter `State` of identifier `Component`? src/App.js:106 106: defaultValue={this.state.noteVal} ^^^^^^^ property `noteVal`. Property cannot be accessed on possibly undefined value 106: defaultValue={this.state.noteVal} ^^^^^^^^^^ undefined. Did you forget to declare type parameter `State` of identifier `Component`? Found 10 errors error Command failed with exit code 2.
Discussions

What does Exit code 2 means when INSTALLING TestComplete 15.46.9.7
I am creating a installation package to install TestComplete 15.46.9., i am using a powershell scriptwith the following installation... More on community.smartbear.com
🌐 community.smartbear.com
2
0
January 4, 2023
The Python process failed (exit code: 2)
The Python process failed (exit code: 2). More info might be available in the logs. But on my another laptop (MAC) and cloud version, I didn't get this error. This is a free edition DSS but with 2-week entreprise trail. More on community.dataiku.com
🌐 community.dataiku.com
November 7, 2023
Command failed with exit code 2 until --fix or disable corresponding rule
Clearly describe the bug Lint fails with exit code 2 on rule violation. Postlint scripts do not run and entire build fails. Which rule, if any, is the bug related to? no-missing-end-of-source-newli... More on github.com
🌐 github.com
2
August 14, 2018
I am getting this error : Result: exit code = 2 SSH command failed. Failing build.
Hi I have a deploy.yml file set up in a bitbucket repository that triggers a bamboo build using SAS. I previously had a SSH key set up with bitbucket but due to a recent issue that has been disabled by admins. The build keeps failing and I keep getting "Result: exit code = 2....... SSH command... More on community.atlassian.com
🌐 community.atlassian.com
February 3, 2025
🌐
Broadcom
knowledge.broadcom.com β€Ί external β€Ί article β€Ί 37196 β€Ί command-job-fails-with-exit-code-2.html
Command Job Fails With Exit Code 2
October 3, 2023 - Because of that, the error wasn't as descriptive as it would have been if executed without the 'exec' command. When the parameter is set to "true", the job's command is executed by a wrapper script that is build by the agent and the logged error becomes much more descriptive of the actual problem. Here is an example of the same job failure with the oscomponent.cmdprefix.force set to "true"...
🌐
SmartBear Community
community.smartbear.com β€Ί smartbear community β€Ί testcomplete β€Ί testcomplete questions
What does Exit code 2 means when INSTALLING TestComplete 15.46.9.7 | SmartBear Community
January 4, 2023 - with the following installation switch Β· "xDir\TestComplete_Tool.exe" -SilentInstall Β· nothing else, and it works like a charm in most machines but some of them are returning 2 as an exit code (checked on my logs) and it fails, but it doesn't say why Β· I tried searching what that exit code for installation means but had no luck, can someone help on this?
🌐
Dataiku Community
community.dataiku.com β€Ί questions & discussions β€Ί using dataiku
The Python process failed (exit code: 2) β€” Dataiku Community
November 7, 2023 - [18:46:22] [INFO] [dku.flow.activity] - Run thread failed for activity recipe_from_notebook_admins_Python_notebook_on_job_postings_prepared_NP com.dataiku.dip.exceptions.ProcessDiedException: The Python process failed (exit code: 2). More info might be available in the logs.
🌐
GitHub
github.com β€Ί stylelint β€Ί stylelint β€Ί issues β€Ί 3535
Command failed with exit code 2 until --fix or disable corresponding rule Β· Issue #3535 Β· stylelint/stylelint
August 14, 2018 - Clearly describe the bug Lint fails with exit code 2 on rule violation. Postlint scripts do not run and entire build fails. Which rule, if any, is the bug related to? no-missing-end-of-source-newli...
Author Β  bm2u
🌐
CodeForGeek
codeforgeek.com β€Ί home β€Ί debugging β€œmake failed with exit code 2” error
Debugging "Make Failed with Exit Code 2" Error | CodeForGeek
December 22, 2023 - Exit code 2 is a generic error code that indicates that a process failed to complete its operation successfully. In Node.js it generally occurs during the installation of modules.
Find elsewhere
Top answer
1 of 2
6

For GNU ls, use the source Luke: http://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=blob;f=src/ls.c;h=bf0c5941d7de699fc5a85d44461ef29192216d9d;hb=HEAD

You will find many cases where the return code is 2, and some are easy to trigger, as shown below.

First you can read in it:

 802 /* Exit statuses.  */
 803 enum
 804   {
 805     /* "ls" had a minor problem.  E.g., while processing a directory,
 806        ls obtained the name of an entry via readdir, yet was later
 807        unable to stat that name.  This happens when listing a directory
 808        in which entries are actively being removed or renamed.  */
 809     LS_MINOR_PROBLEM = 1,
 810 
 811     /* "ls" had more serious trouble (e.g., memory exhausted, invalid
 812        option or failure to stat a command line argument.  */
 813     LS_FAILURE = 2
 814   };

So you can see already that value 2 covers more cases than what is written in the documentation.

Then if you search further for LS_FAILURE in the code you find out about different cases:

Case 1

1896         case 'w':
1897           if (! set_line_length (optarg))
1898             die (LS_FAILURE, 0, "%s: %s", _("invalid line width"),
1899                  quote (optarg));
1900           break;

set_line_length will react depending on how xstrtoumax returns for the given width. If you look closer at the source code of it you can arrive at some edge cases:

$ ls -w -1 >& /dev/null
$ echo  ls -w 1 >& /dev/null
$ echo $?
0

Case 2

1964         case 'T':
1965           tabsize = xnumtoumax (optarg, 0, 0, SIZE_MAX, "",
1966                                 _("invalid tab size"), LS_FAILURE);
1967           break;

Similar to previous case:

$ ls -T 1 >& /dev/null
$ echo  ls -T -1 >& /dev/null
$ echo $?
2

Case 3

2106         default:
2107           usage (LS_FAILURE);

So that is the default error code if you provide invalid parameters. See this example:

$ ls --unknown-option >& /dev/null
$ echo $?
2

Case 4

2198               if (strchr (p1 + 1, '\n'))
2199                 die (LS_FAILURE, 0, _("invalid time style format %s"),
2200                      quote (p0));

This happens when you are providing invalid time format, with two \n:

$ ls -l --time-style=+%T >& /dev/null ; echo  ls -l --time-style=+%T$'\n' >& /dev/null ; echo  ls -l --time-style=+%T$'\n'%T >& /dev/null ; echo  ls -l --time-style=+%T$'\n'%T$'\n' >& /dev/null ; echo $?
2

Case 5

2218               /* The following is a manual expansion of argmatch_valid,
2219                  but with the added "+ ..." description and the [posix-]
2220                  prefixes prepended.  Note that this simplification works
2221                  only because all four existing time_style_types values
2222                  are distinct.  */
2223               fputs (_("Valid arguments are:\n"), stderr);
2224               char const *const *p = time_style_args;
2225               while (*p)
2226                 fprintf (stderr, "  - [posix-]%s\n", *p++);
2227               fputs (_("  - +FORMAT (e.g., +%H:%M) for a 'date'-style"
2228                        " format\n"), stderr);
2229               usage (LS_FAILURE);

Triggered when using invalid time format name:

$ LANG=C ls -l --time-style=whatever 
ls: invalid argument 'whatever' for 'time style'
Valid arguments are:
  - [posix-]full-iso
  - [posix-]long-iso
  - [posix-]iso
  - [posix-]locale
  - +FORMAT (e.g., +%H:%M) for a 'date'-style format
Try 'ls --help' for more information.

$ echo $?
2

Case 6

2669 static void
2670 set_exit_status (bool serious)
2671 {
2672   if (serious)
2673     exit_status = LS_FAILURE;
2674   else if (exit_status == EXIT_SUCCESS)
2675     exit_status = LS_MINOR_PROBLEM;
2676 }

This (serious = true) can happen in multiple cases, for example if there is a loop somewhere:

2747       /* If we've already visited this dev/inode pair, warn that
2748          we've found a loop, and do not process this directory.  */
2749       if (visit_dir (dir_stat.st_dev, dir_stat.st_ino))
2750         {
2751           error (0, 0, _("%s: not listing already-listed directory"),
2752                  quotef (name));
2753           closedir (dirp);
2754           set_exit_status (true);
2755           return;
2756         }

It can also happen for many other cases, based on arguments. file_failure first argument is the boolean passed to set_exit_status

Subcase A

2710 /* Read directory NAME, and list the files in it.
2711    If REALNAME is nonzero, print its name instead of NAME;
2712    this is used for symbolic links to directories.
2713    COMMAND_LINE_ARG means this directory was mentioned on the command line.  */

...

2725   if (!dirp)
2726     {
2727       file_failure (command_line_arg, _("cannot open directory %s"), name);
2728       return;
2729     }

So for example:

$ ls /thatDOESnotEXIST >& /dev/null
$ echo $?
2

Subcase B

2736       /* If dirfd failed, endure the overhead of using stat.  */
2737       if ((0 <= fd
2738            ? fstat (fd, &dir_stat)
2739            : stat (name, &dir_stat)) < 0)
2740         {
2741           file_failure (command_line_arg,
2742                         _("cannot determine device and inode of %s"), name);

That is some kind of directory not available to access (like a remote one).

Subcase C

2771       if (print_hyperlink)
2772         {
2773           absolute_name = canonicalize_filename_mode (name, CAN_MISSING);
2774           if (! absolute_name)
2775             file_failure (command_line_arg,
2776                           _("error canonicalizing %s"), name);

or

3189       if (print_hyperlink)
3190         {
3191           f->absolute_name = canonicalize_filename_mode (full_name,
3192                                                          CAN_MISSING);
3193           if (! f->absolute_name)
3194             file_failure (command_line_arg,
3195                           _("error canonicalizing %s"), full_name);

or

3450 static void
3451 get_link_name (char const *filename, struct fileinfo *f, bool command_line_arg)
3452 {
3453   f->linkname = areadlink_with_size (filename, f->stat.st_size);
3454   if (f->linkname == NULL)
3455     file_failure (command_line_arg, _("cannot read symbolic link %s"),
3456                   filename);
3457 }

These are some kind of broken hard/soft links.

Subcase D

2836       else if (errno != 0)
2837         {
2838           file_failure (command_line_arg, _("reading directory %s"), name);

or

2851   if (closedir (dirp) != 0)
2852     {
2853       file_failure (command_line_arg, _("closing directory %s"), name);

Another case when it is not possible to read directory content (if provided on command line)

Subcase E

3235       if (err != 0)
3236         {
3237           /* Failure to stat a command line argument leads to
3238              an exit status of 2.  For other files, stat failure
3239              provokes an exit status of 1.  */
3240           file_failure (command_line_arg,
3241                         _("cannot access %s"), full_name);

That happens when trying to match files, such as:

$ ls '*DOESnotEXIST*' >& /dev/null
$ echo $?
2
2 of 2
3

Yes, man ls (for GNU ls) contains:

2 if serious trouble (e.g., cannot access command-line argument).

Probably, the word access should be read as stat. An argument (file) that could not be stat (stat filename) because it doesn't exists, would generate an error code of 2.

In short, for GNU ls: A command like:

ls   NONE_existent_file    # will result in exit 2

Try:

ls nofile
ls: cannot access nofile: No such file or directory
echo $?
2

Or try:

(date); echo "exit status: $?"
ls: cannot access 'Wed': No such file or directory
ls: cannot access 'Oct': No such file or directory
ls: cannot access '24': No such file or directory
ls: cannot access '02:42:02': No such file or directory
ls: cannot access 'UTC': No such file or directory
ls: cannot access '2018': No such file or directory
exit status: 2
🌐
GitHub
github.com β€Ί actions β€Ί setup-node β€Ί issues β€Ί 116
[error]The process '/bin/tar' failed with exit code 2 Β· Issue #116 Β· actions/setup-node
February 24, 2020 - /bin/tar xz --warning=no-unknown-keyword -C /home/runner/work/_temp/2036e974-4339-482b-82eb-cdb09db0a167 -f /home/runner/work/_temp/f37bd59e-bdbe-4b4d-a5c2-6e0540d2eca3 gzip: stdin: unexpected end of file /bin/tar: Unexpected EOF in archive /bin/tar: Unexpected EOF in archive ##[error]The process '/bin/tar' failed with exit code 2
Author Β  bluelovers
🌐
Fivetran
fivetran.com β€Ί docs β€Ί hvr6 β€Ί faq β€Ί errors-warnings-alerts β€Ί exit-code-2
Error - Operating System Command Failed With Exit Code 2
Operating System command '/usr/bin/perl /opt/fivetran/hvr_home/script/hvralert.pl -t alert_test' failed with exit code 2.
🌐
Netlify
answers.netlify.com β€Ί support
Command failed with exit code 2: npm run build - Support - Netlify Support Forums
September 9, 2023 - Hi, I got a problem during deployment if I could get help how to solve it please 9:49:53 PM: Netlify Build 9:49:53 PM: ──────────────────────────────────────────────────────────────── 9:49:53 PM: ​ 9:49:53 PM: ❯ Version 9:49:53 PM: @netlify/build 29.20.12 9:49:53 PM: ​ 9:49:53 PM: ❯ Flags 9:49:53 PM: baseRelDir: true 9:49:53 PM: buildId: 64fbf9575e5dc31f8e7bc226 9:49:53 PM: deployId: 64fbf9575e5dc31f8e7bc228 9:49:53 PM: ​ 9:49:53 PM: ❯ Cu...
🌐
Reddit
reddit.com β€Ί r/sccm β€Ί application deployment exit code 2 | cmd
r/SCCM on Reddit: Application Deployment Exit Code 2 | cmd
April 11, 2022 -

hello guys,

i want to publish an application ,which uses net use to permanently map a network drive to the user.

Installation behavior is: Install for user because the user who clicks it in softwarecenter should have it mapped.

Install: cmd /c drive.bat

drive.bat: net use o: \\ger06\drv2 /persistent:Yes

Error: Unmatched exit code (2) is considered an execution failure.

Detection is working, but the enforcement is failing.

Who has an Idea?

🌐
Netlify
answers.netlify.com β€Ί support
Build Fail with exit code 2 - Support - Netlify Support Forums
December 25, 2022 - I recently migrated to vite. After which builds are failing. npm run build worked on local I searched on google and netlify docs, but none of them worked. Please do help me here. Site name: https://socialgram.netlify.app/ Deploy logs 2:13:53 AM: $ npm run build 2:13:53 AM: > socialgram@1.1.0 build /opt/build/repo 2:13:53 AM: > vite build 2:13:53 AM: (node:3377) ExperimentalWarning: The ESM module loader is experimental.
🌐
Stack Overflow
stackoverflow.com β€Ί questions β€Ί 76576454 β€Ί failed-with-exit-code-2-error-when-attempting-to-install-python-package
windows - "Failed with exit code 2" Error when attempting to install python package - Stack Overflow
error message: error: Setup script exited with error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.36.32532\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
🌐
Render
community.render.com β€Ί t β€Ί server-failed-with-exit-status-2 β€Ί 921
Server failed with exit status 2 - Render
March 2, 2021 - I have a Go-based private service (with HTTP listener) that fails several times per hour with Server failed Exited with status 2 and then immediately β€œServer back up”. The service is on a 1 GB plan but uses only around…
🌐
GitHub
github.com β€Ί argoproj β€Ί argo-workflows β€Ί issues β€Ί 14577
Pod failed with exit code 2 even though executed and saved output artifact correctly - no logs from sidecar Β· Issue #14577 Β· argoproj/argo-workflows
June 18, 2025 - A cron workflow failed, especially one particular pod with exit code 2 even though the execution of logic inside of the pod has been conducted correctly.
Author Β  macieksalwowski