Jenkins with yarn and private package dependency fails

Any idea why react project that uses yarn for dependencies and has a private project like https://:@bitbucket.<org.domanin>/scm//-lib.git in package.json fails in Jenkins? Locally I can build - no problems.

The error looks lie that:

error Command failed.
Exit code: 128
Command: git
Arguments: clone https://:@bitbucket.<org.domanin>/scm//-lib.git
C:\Windows\system32\config\systemprofile\AppData\Local\Yarn\Cache\v6.tmp\8c12210546bb0e4f4a20955057b494af
Directory: C:\ProgramData\Jenkins.jenkins\workspace<branch>\ui
Output:
fatal: destination path ‘C:\Windows\system32\config\systemprofile\AppData\Local\Yarn\Cache\v6.tmp\8c12210546bb0e4f4a20955057b494af’ already exists and is not an empty directory.
info Visit yarn install | Yarn for documentation about this command.
node:internal/modules/cjs/loader:936
throw err;
^

Error: Cannot find module ‘C:\ProgramData\Jenkins.jenkins\workspace<branch>\ui\node_modules\react-scripts\bin\react-scripts.js’
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47 {
code: ‘MODULE_NOT_FOUND’,
requireStack:
}

This seems to be the crux of the problem, and not really a jenkins issue.

Looks like one solution is to set a new cache folder? Yarn Upgrade fails when cache isn't clean · Issue #2396 · yarnpkg/yarn · GitHub

Maybe something inside of the job itself so there’s never conflicts. $WORKSPACE env variable will always point to this specific job’s directory.

Thanks a lot. It worked.