I am using Custom Tool plugin in Jenkins to run Salesforce CLI to execute my JenkinsFile.
- https://developer.salesforce.com/tools/salesforcecli
- https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_install_cli.htm (Also here)
However I get the following error when running my job. I believe I am using the correct URL but unsure why it has a problem running the CLI. Any help appreciated
Unpacking https://developer.salesforce.com/media/salesforce-cli/sf/channels/stable/sf-x64.exe to /Users/mmann/.jenkins/tools/com.cloudbees.jenkins.plugins.customtools.CustomTool/toolbelt on Jenkins
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
java.io.IOException: incorrect header check
at com.jcraft.jzlib.InflaterInputStream.read(InflaterInputStream.java:112)
at org.apache.commons.compress.utils.IOUtils.readFully(IOUtils.java:244)
at org.apache.commons.compress.utils.IOUtils.readFully(IOUtils.java:212)
at org.apache.commons.compress.archivers.tar.TarArchiveInputStream.readRecord(TarArchiveInputStream.java:744)
at org.apache.commons.compress.archivers.tar.TarArchiveInputStream.getRecord(TarArchiveInputStream.java:543)
at org.apache.commons.compress.archivers.tar.TarArchiveInputStream.getNextTarEntry(TarArchiveInputStream.java:456)
at hudson.FilePath.readFromTar(FilePath.java:3043)
Caused: java.io.IOException: Failed to extract input stream
at hudson.FilePath.readFromTar(FilePath.java:3068)
at hudson.FilePath$UntarFrom.invoke(FilePath.java:942)
at hudson.FilePath$UntarFrom.invoke(FilePath.java:931)
at hudson.FilePath.act(FilePath.java:1198)
at hudson.FilePath.act(FilePath.java:1181)
at hudson.FilePath.untarFrom(FilePath.java:927)
at hudson.FilePath.installIfNecessaryFrom(FilePath.java:1059)
Caused: java.io.IOException: Failed to unpack https://developer.salesforce.com/media/salesforce-cli/sf/channels/stable/sf-x64.exe (1371 bytes read of total 59276112)
at hudson.FilePath.installIfNecessaryFrom(FilePath.java:1061)
Also: org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: dd512faa-339f-4d65-a771-7d230a8e6bf4
Caused: java.io.IOException: Failed to install https://developer.salesforce.com/media/salesforce-cli/sf/channels/stable/sf-x64.exe to /Users/mmann/.jenkins/tools/com.cloudbees.jenkins.plugins.customtools.CustomTool/toolbelt
at hudson.FilePath.installIfNecessaryFrom(FilePath.java:1067)
at hudson.FilePath.installIfNecessaryFrom(FilePath.java:980)
at hudson.tools.ZipExtractionInstaller.performInstallation(ZipExtractionInstaller.java:86)
at hudson.tools.InstallerTranslator.getToolHome(InstallerTranslator.java:70)
at hudson.tools.ToolLocationNodeProperty.getToolHome(ToolLocationNodeProperty.java:109)
at hudson.tools.ToolInstallation.translateFor(ToolInstallation.java:221)
at com.cloudbees.jenkins.plugins.customtools.CustomTool.forNode(CustomTool.java:164)
at com.cloudbees.jenkins.plugins.customtools.CustomTool.forNode(CustomTool.java:66)
at org.jenkinsci.plugins.workflow.steps.ToolStep$Execution.run(ToolStep.java:157)
at org.jenkinsci.plugins.workflow.steps.ToolStep$Execution.run(ToolStep.java:138)
at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)
Finished: FAILURE
Edit:
Updating code based on answers:
pipeline {
agent any
environment {
// Define Salesforce CLI URL
SALESFORCE_CLI_URL = 'https://developer.salesforce.com/media/salesforce-cli/sf/channels/stable/sf-x64.exe'
}
stages {
stage('Install Salesforce CLI') {
steps {
// Download Salesforce CLI
sh "curl -o sf-cli.exe ${env.SALESFORCE_CLI_URL}"
// Make the downloaded CLI executable
sh "chmod +x sf-cli.exe"
}
}
stage('Run Salesforce CLI Command') {
steps {
// Use the withCredentials block to access the secret text credentials
withCredentials([
string(
credentialsId: 'HUB_ORG_DH',
variable: 'HUB_ORG'
),
string(
credentialsId: 'SFDC_HOST_DH',
variable: 'SFDC_HOST'
),
string(
credentialsId: 'JWT_CRED_ID_DH',
variable: 'JWT_KEY_CRED_ID'
),
string(
credentialsId: 'CONNECTED_APP_CONSUMER_KEY_DH',
variable: 'CONNECTED_APP_CONSUMER_KEY'
)
]) {
// Now you can use the environment variables directly within this block
sh "./sf-cli.exe auth:jwt:grant --clientid \$CONNECTED_APP_CONSUMER_KEY --username \$HUB_ORG --jwtkeyfile \$JWT_KEY_CRED_ID --setdefaultdevhubusername --instanceurl \$SFDC_HOST"
}
}
}
}
}
I receive the following error. Not sure about which binary to use:
[Pipeline] sh
+ chmod +x sf-cli.exe
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Run Salesforce CLI Command)
[Pipeline] withCredentials
Masking supported pattern matches of $HUB_ORG or $SFDC_HOST or $JWT_KEY_CRED_ID or $CONNECTED_APP_CONSUMER_KEY
[Pipeline] {
[Pipeline] sh
+ ./sf-cli.exe auth:jwt:grant --clientid **** --username **** --jwtkeyfile **** --setdefaultdevhubusername --instanceurl ****
/Users/mmann/.jenkins/workspace/Production_Release_@tmp/durable-39743792/script.sh: line 1: ./sf-cli.exe: cannot execute binary file
[Pipeline] }