Jenkins中Custom Tool插件部署Salesforce CLI遇执行错误求助
解决Jenkins中Salesforce CLI的兼容与执行问题
问题根源分析
你的Jenkins运行在macOS系统(从路径/Users/mmann/.jenkins可判断),但你选择了Windows版本的Salesforce CLI(sf-x64.exe),导致两个关键错误:
- Custom Tool插件报错:插件将exe文件当作压缩包解压,但exe是Windows安装程序,并非标准压缩格式,因此抛出
incorrect header check错误。 - 直接执行报错:macOS无法运行Windows二进制文件,所以提示
cannot execute binary file。
解决方案
需要针对macOS系统选择对应的Salesforce CLI安装方式,以下提供两种可靠方案:
方案1:使用官方自动安装脚本(推荐)
官方脚本会自动识别操作系统并安装对应版本,无需手动选择二进制:
pipeline { agent any stages { stage('Install Salesforce CLI') { steps { sh "curl -s https://developer.salesforce.com/media/salesforce-cli/sf/install.sh | sh" } } stage('Run Salesforce CLI Command') { steps { 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') ]) { sh "sf auth:jwt:grant --clientid \$CONNECTED_APP_CONSUMER_KEY --username \$HUB_ORG --jwtkeyfile \$JWT_KEY_CRED_ID --setdefaultdevhubusername --instanceurl \$SFDC_HOST" } } } } }
方案2:手动下载macOS版本的二进制
如果你需要指定版本或离线安装,下载macOS的tar.gz包并解压:
pipeline { agent any environment { // macOS x64版本的Salesforce CLI压缩包 SALESFORCE_CLI_URL = 'https://developer.salesforce.com/media/salesforce-cli/sf/channels/stable/sf-darwin-x64.tar.gz' } stages { stage('Install Salesforce CLI') { steps { sh "curl -o sf-cli.tar.gz ${env.SALESFORCE_CLI_URL}" sh "tar -xzf sf-cli.tar.gz -C /usr/local/bin" sh "chmod +x /usr/local/bin/sf" } } stage('Run Salesforce CLI Command') { steps { 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') ]) { sh "sf auth:jwt:grant --clientid \$CONNECTED_APP_CONSUMER_KEY --username \$HUB_ORG --jwtkeyfile \$JWT_KEY_CRED_ID --setdefaultdevhubusername --instanceurl \$SFDC_HOST" } } } } }
补充:Custom Tool插件的正确用法
如果坚持使用Custom Tool插件,需要配置:
- 选择macOS版本的
sf-darwin-x64.tar.gz作为工具包URL - 配置解压路径,确保Jenkins能正确提取二进制文件到工具目录
内容的提问来源于stack exchange,提问作者some guy
相关产品推荐
相关产品推荐

