1

I am trying to connect Jenkins to the SF sandbox. I am stuck on the auth step, where I receive this kind of error:

ERROR running auth:jwt:grant:  Unexpected argument: Pipeline@tmp/secretFiles/e56a52e6-fad5-41c3-b303-1e53a98632a0/server.key
See more help with --help

My Jenkinsfile command:

            withEnv(["HOME=${env.WORKSPACE}"]) {
                    withCredentials([file(credentialsId: '3526cc73-4827-4bae-9d6a-a9dd40ecc765', variable: 'server_key_file')]) {
                        // -------------------------------------------------------------------------
                        // Authenticate to Salesforce using the server key.
                        // -------------------------------------------------------------------------

                        stage('Authorize to Salesforce') {
                            rc = command "/usr/local/bin/sfdx auth:jwt:grant --instanceurl ${SF_INSTANCE_URL} --clientid ${SF_CONSUMER_KEY} --username ${SF_USERNAME} --setalias partial -f $server_key_file"

I tried different workarounds, including replacing $server_key_file with the actual path to the servey.key on my machine. No use.

Meanwhile, I can successfully connect to the org from the terminal:

****** JWT % sfdx auth:jwt:grant --clientid ********************************** \
--jwtkeyfile server.key --username ***************
Successfully authorized *************** with org ID *************

I quadruple-checked if the consumer key is correct. I re-created the connected app in SF. I tried to add the file to the pipeline parameters. Still no use.

Please help, I ran out of ideas.

3 Answers 3

1

The "f" flag for this command only uses a single dash

so it's -f <keyfile>
and not --f <keyfile> as you currently have

Double-dashes are generally used for flags that are words, whereas single-dashes are generally used for flags that are single letters

2
  • Thank you for the reply! It was a --jwtkeyfile there before, I fixed the string. Still, the same error. Commented Aug 17, 2022 at 13:34
  • @OleksandrHoncharuk Also, any spaces in an argument means you'll need to enclose the argument in quotes. Not familiar enough with Jenkins to know how rc = command " ..." behaves.
    – Derek F
    Commented Aug 17, 2022 at 13:41
0

Try this and replace the necessary fields

def SF_CONSUMER_KEY=env.SF_CONSUMER_KEY
def SF_USERNAME=env.SF_USERNAME
def SERVER_KEY_CREDENTALS_ID=env.SERVER_KEY_CREDENTALS_ID
def SF_INSTANCE_URL = env.SF_INSTANCE_URL ?: "https://login.salesforce.com"

def toolbelt = tool 'toolbelt'

// ------------------------------------------------------------------------- // Run all the enclosed stages with access to the Salesforce // JWT key credentials. // -------------------------------------------------------------------------

withEnv(["HOME=${env.WORKSPACE}"]) {
    
    withCredentials([file(credentialsId: SERVER_KEY_CREDENTALS_ID, variable: 'server_key_file')]) {

        // -------------------------------------------------------------------------
        // Authorize the Dev Hub org with JWT key and give it an alias.
        // -------------------------------------------------------------------------

        stage('Authorize DevHub') {
            rc = command "${toolbelt}/sfdx auth:jwt:grant --instanceurl ${SF_INSTANCE_URL} --clientid ${SF_CONSUMER_KEY} --username ${SF_USERNAME} --jwtkeyfile ${server_key_file} --setdefaultdevhubusername --setalias HubOrg"
            if (rc != 0) {
                error 'Salesforce dev hub org authorization failed.'
            }
        }
1
  • Thank you for the reply! Could you, please, show your setup for the toolbelt, if possible? Commented Aug 19, 2022 at 11:36
0

It seems invalid path issue. Check if your workspace(job) name includes spaces. This issue might be due to same. Remove spaces and then try.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .