我通過自定義工具插件在Jenkins中定義了一個自定義工具。如果我創建自由式項目,Install custom tools
選件在執行期間正確找到並使用該工具(Salesforce DX)。Jenkins管道 - 如何使用「工具」選項指定自定義工具?
但是,我找不到通過管道文件做同樣的方法。我已經使用管道語法片斷髮生器獲得:
tool name: 'sfdx', type: 'com.cloudbees.jenkins.plugins.customtools.CustomTool'
我已經將它放入我的舞臺定義:
stage('FetchMetadata') { print 'Collect Prod metadata via SFDX' tool name: 'sfdx', type: 'com.cloudbees.jenkins.plugins.customtools.CustomTool' sh('sfdx force:mdapi:retrieve -r metadata/ -u DevHub -k ./metadata/package.xml') }
,但我得到一個錯誤信息,說明line 2: sfdx: command not found
有沒有其他的方法我應該使用這個片段?
全部Jenkinsfile的信息:
node { currentBuild.result = 'SUCCESS'
try {
stage('CheckoutRepo') {
print 'Get the latest code from the MASTER branch'
checkout scm
}
stage('FetchMetadata') {
print 'Collect Prod metadata via SFDX'
tool name: 'sfdx', type: 'com.cloudbees.jenkins.plugins.customtools.CustomTool'
sh('sfdx force:mdapi:retrieve -r metadata/ -u DevHub -k ./metadata/package.xml')
}
stage('ConvertMetadata') {
print 'Unzip retrieved metadata file'
sh('unzip unpackaged.zip .')
print 'Convert metadata to SFDX format'
sh('/usr/local/bin/sfdx force:mdapi:convert -r metadata/unpackaged/ -d force-app/')
}
stage('CommitChanges') {
sh('git add --all')
print 'Check if any changes need committing'
sh('if ! git diff-index --quiet HEAD --; then echo "changes found - pushing to repo"; git commit -m "Autocommit from Prod @ $(date +%H:%M:%S\' \'%d/%m/%Y)"; else echo "no changes found"; fi')
sshagent(['xxx-xxx-xxx-xxx']) {
sh('git push -u origin master')
}
}
}
catch (err) {
currentBuild.result = 'FAILURE'
print 'Build failed'
error(err)
}
}
UPDATE 我已經使用this example Jenkinsfile 我現在的階段取得了一些進展看起來是這樣的: stage('FetchMetadata') { print 'Collect Prod metadata via SFDX' def sfdxLoc = tool 'sfdx' sh script: "cd topLevel; ${sfdxLoc}/sfdx force:mdapi:retrieve -r metadata/ -u DevHub -k ./metadata/package.xml" }
不幸的是,雖然它看起來像詹金斯現在發現和運行sfdx工具,我得到一個新的錯誤:
TypeError: Cannot read property 'run' of undefined at Object.<anonymous> (/var/lib/jenkins/.cache/sfdx/tmp/heroku-script-509584048:20:4) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.runMain (module.js:604:10) at run (bootstrap_node.js:394:7) at startup (bootstrap_node.js:149:9) at bootstrap_node.js:509:3