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
apiuser@demo.com.uat
[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 apiuser@demo.com.uat --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.
In the output near the auth command, I am seeing two double-quotes. I need some help to fix the jenkinsfile.