0

I am trying to use Jenkins for my project CI. I followed the salesforce document and a few blogs for the setup. Here is my Jenkinsfile:

#!groovy
import groovy.json.JsonSlurperClassic
node {

    def BUILD_NUMBER=env.BUILD_NUMBER
    def RUN_ARTIFACT_DIR="tests/${BUILD_NUMBER}"
    def SFDC_USERNAME

    def HUB_ORG=env.HUB_ORG_DH
    def SFDC_HOST = env.SFDC_HOST_DH
    def JWT_KEY_CRED_ID = env.JWT_CRED_ID_DH
    def CONNECTED_APP_CONSUMER_KEY=env.CONNECTED_APP_CONSUMER_KEY_DH

    def toolbelt = tool 'toolbelt'

    stage('checkout source') {
        // when running in multi-branch job, one must issue this command
        checkout scm
    }

    withCredentials([file(credentialsId: JWT_KEY_CRED_ID, variable: 'jwt_key_file')]) {
        stage('Deploye Code') {
            if (isUnix()) {
                rc = sh returnStatus: true, script: "${toolbelt} force:auth:jwt:grant --clientid ${CONNECTED_APP_CONSUMER_KEY} --username ${HUB_ORG} --jwtkeyfile ${jwt_key_file} --setdefaultdevhubusername --instanceurl ${SFDC_HOST}"
            }else{
                 rc = bat returnStatus: true, script: "\"${toolbelt}\" force:auth:jwt:grant --clientid ${CONNECTED_APP_CONSUMER_KEY} --username ${HUB_ORG} --jwtkeyfile \"${jwt_key_file}\" --setdefaultdevhubusername --instanceurl ${SFDC_HOST}"
                 println rc
            }
            if (rc != 0) { error 'hub org authorization failed' }
        }
    }
}

The Output:

Checking out git https://github.com/JenSetup/UATSETHUDPOC into C:\Program Files (x86)\Jenkins\workspace\UATCI_MasterBranch@script to read Jenkinsfile
No credentials specified
 > git.exe rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git.exe config remote.origin.url https://github.com/JenSetup/UATSETHUDPOC # timeout=10
Fetching upstream changes from https://github.com/JenSetup/UATSETHUDPOC
 > git.exe --version # timeout=10
 > git.exe fetch --tags --force --progress https://github.com/JenSetup/UATSETHUDPOC +refs/heads/*:refs/remotes/origin/*
 > git.exe rev-parse "refs/remotes/origin/master^{commit}" # timeout=10
 > git.exe rev-parse "refs/remotes/origin/origin/master^{commit}" # timeout=10
Checking out Revision ada0ac3260bb60fed646cddaf7b6fe6cc8ca49d8 (refs/remotes/origin/master)
 > git.exe config core.sparsecheckout # timeout=10
 > git.exe checkout -f ada0ac3260bb60fed646cddaf7b6fe6cc8ca49d8
Commit message: "update"
 > git.exe rev-list --no-walk 55ab415e6fb70147c6e6fbb5e68ce31826b5231a # timeout=10
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in C:\Program Files (x86)\Jenkins\workspace\UATCI_MasterBranch
[Pipeline] {
[Pipeline] echo
KEY IS
[Pipeline] echo
dcc01b3d-7295-468c-9718-18ab13c2e6c0
[Pipeline] echo
[email protected]
[Pipeline] echo
https://jensetup-demo--uat.my.salesforce.com
[Pipeline] echo
3MVG9MHOv_bskkhR7s6E55zdqo_7o2vAbW9Vzy6.7wde5x.oIbIQ5djo5O49.PsG7oDg6pFDkYvtFY4pYj40.
[Pipeline] tool
Installer "Extract *.zip/*.tar.gz" cannot be used to install "toolbelt" on the node "Jenkins"
[Pipeline] stage
[Pipeline] { (checkout source)
[Pipeline] checkout
No credentials specified
 > git.exe rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git.exe config remote.origin.url https://github.com/JenSetup/UATSETHUDPOC # timeout=10
Fetching upstream changes from https://github.com/JenSetup/UATSETHUDPOC
 > git.exe --version # timeout=10
 > git.exe fetch --tags --force --progress https://github.com/JenSetup/UATSETHUDPOC +refs/heads/*:refs/remotes/origin/*
 > git.exe rev-parse "refs/remotes/origin/master^{commit}" # timeout=10
 > git.exe rev-parse "refs/remotes/origin/origin/master^{commit}" # timeout=10
Checking out Revision ada0ac3260bb60fed646cddaf7b6fe6cc8ca49d8 (refs/remotes/origin/master)
 > git.exe config core.sparsecheckout # timeout=10
 > git.exe checkout -f ada0ac3260bb60fed646cddaf7b6fe6cc8ca49d8
Commit message: "update"
[Pipeline] }
[Pipeline] // stage
[Pipeline] withCredentials
Masking supported pattern matches of %jwt_key_file%
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Deploye Code)
[Pipeline] isUnix
[Pipeline] bat

C:\Program Files (x86)\Jenkins\workspace\UATCI_MasterBranch>""auth:jwt:grant --clientid 3MVG9MHOv_bskkhR7s6E55zdqo_7o2vAbW9Vzy6.7wde5x.oIbIQ5djo5O49.PsG7oDg6pFDkYvtFY4pYj40. --username [email protected] --jwtkeyfile "****" --setdefaultdevhubusername --instanceurl https://jensetup-demo--uat.my.salesforce.com 
The filename, directory name, or volume label syntax is incorrect.
[Pipeline] echo
1
[Pipeline] error
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: hub org authorization failed
Finished: FAILURE

I am not able to find what is the error with jenkinsfile.

When I try the auth command in CLI I am able to authorize the org.

enter image description here

In the output near the auth command, I am seeing two double-quotes. I need some help to fix the jenkinsfile.

1 Answer 1

1

The Error that you are getting is because of ${toolbelt} be sure that you have installed the sfdx in your Jenkins under Global Tools configuration. You can refer below link for the same: Install SalesforceDX CLI for Jenkins builds Also, if you have configured the sfdx into your local machine you can try below command to test

if (isUnix()) {
            rc = sh returnStatus: true, script: "sfdx force:auth:jwt:grant --clientid ${CONNECTED_APP_CONSUMER_KEY} --username ${HUB_ORG} --jwtkeyfile ${jwt_key_file} -d --instanceurl ${SFDC_HOST}"
        } else {
            rc = bat returnStatus: true, script: "sfdx force:auth:jwt:grant --clientid ${CONNECTED_APP_CONSUMER_KEY} --username ${HUB_ORG} --jwtkeyfile \"${jwt_key_file}\" -d --instanceurl ${SFDC_HOST}"
        }

        if (rc != 0) {
            error 'hub org authorization failed'
        }

Let us know if this works for you :)

4
  • Hi Amit, thanks for the reply. The issue is with the login URL. Salesforce is looking for login.salesforce or test.salesforce. I had my custom URL that was the issue. I am able to Authorize. I am working on validation and deployment code.
    – Tamil
    Sep 12, 2019 at 2:43
  • hi @Tamil is the sfdx deploy is working for you in Jenkins? Nov 11, 2021 at 19:23
  • 2
    Hey @KumaraRavuri yes : "sfdx force:source:deploy -u ${SF_INSTANCE_URL_USERNAME} -x manifest/${env.SF_PACKAGE_NAME}.xml -w 30 --loglevel ${env.LOGLEVEL} --testlevel RunLocalTests"
    – Tamil
    Nov 16, 2021 at 18:03
  • @Tamil -I have used the same command and it is working for me as well.Thanks alot for responding. Nov 16, 2021 at 20:03

You must log in to answer this question.

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