Salesforce Sandbox authorization issue from jenkins pipeline

Hi,

Using jenkins pipeline for deployment using SFDX-cli and ANT
I’m getting this below error, searched internet a whole lot but not getting any help.

Note: Authorization of salesforce sandbox is succesfully happening from CLI bit not from jenkins pipeline, not sure whats the issue, can you please help.

Uninstalled and installed sfdx-cli but not helped.
let me know if you need any more details on this issue.

error:
[echo] “warnings”: ,
[echo] “commandName”: “Grant”
[echo] }
[echo] Auth Error :
[echo] Auth Result : 1
[echo] Auth Result Response: {
[echo] “status”: 1,
[echo] “name”: “JwtGrant”,
[echo] “message”: “We encountered a JSON web token error, which is likely not an issue with Salesforce CLI. Here’s the error: Unexpected end of JSON input”,
[echo] “exitCode”: 1,
[echo] “context”: “Grant”,
[echo] “stack”: "JwtGrant: We encountered a JSON web token error, which is likely not an issue with Salesforce CLI. Here’s the error: Unexpected end of JSON input\n at Function.wrap (C:\Program Files\sfdx\client\node_modules\@salesforce\command\node_modules\@salesforce\core\lib\sfError.js:61:25)\n

Regards
Ran

It is hard to tell without some more information, ideally pipeline code to reproduce the problem.

Sounds like an Env problem. One user your testing with has the CLI working but the one Jenkins is using doesn’t have it working

any inputs where to check exactly,

In VM environemnt:
below is the command line and its output with exact error, the same error we are seeing in jenkins job also

where xxxxxx … in below command is my client Id


 MINGW64 /c/Program Files (x86)/Jenkins/workspace/Deployment/certificate 
$ sfdx auth:jwt:grant --clientid xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --jwtkeyfile server.key --username myUser@myOrg.com --instanceurl https://test.salesforce.com --json --loglevel error
{
  "status": 1,
  "name": "JwtGrant",
  "message": "We encountered a JSON web token error, which is likely not an issue with Salesforce CLI. Here’s the error: EPERM: operation not permitted, mkdir 'C:\\Program Files (x86)\\Jenkins\\workspace\\Deployment\\.sf'",
  "exitCode": 1,
  "context": "Grant",
  "stack": "JwtGrant: We encountered a JSON web token error, which is likely not an issue with Salesforce CLI. Here’s the error: EPERM: operation not permitted, mkdir 'C:\\Program Files (x86)\\Jenkins\\workspace\\Deployment\\.sf'\n    at Function.wrap (C:\\Program Files\\sfdx\\client\\node_modules\\@salesforce\\command\\node_modules\\@salesforce\\core\\lib\\sfError.js:61:25)\n    at Grant.catch (C:\\Program Files\\sfdx\\client\\node_modules\\@salesforce\\command\\lib\\sfdxCommand.js:267:38)\n    at async Grant._run (C:\\Program Files\\sfdx\\client\\node_modules\\@salesforce\\command\\lib\\sfdxCommand.js:93:13)\n    at async Config.runCommand (C:\\Program Files\\sfdx\\client\\node_modules\\@oclif\\config\\lib\\config.js:173:24)\n    at async SfdxMain.run (C:\\Program Files\\sfdx\\client\\node_modules\\@oclif\\command\\lib\\main.js:27:9)\n    at async SfdxMain._run (C:\\Program Files\\sfdx\\client\\node_modules\\@oclif\\command\\lib\\command.js:43:20)\n    at async Object.run (C:\\Program Files\\sfdx\\client\\dist\\cli.js:162:47)",
  "warnings": [],
  "commandName": "Grant"
}


Local Env above command is working fine.

You have an access right problem. Check if the user doing this (jenkins, agent or otherwise) has access rights to write there. If it is C:\\Program Files (x86) you might need some admin rights on a Windows box. I’d suggest to move your workspace somewhere else.