我正在使用ant部署来构建我的package.xml以进行Salesforce部署。
目标是: sf_build
构建文件在我的工作空间内:
C:\ Jenkins \ workspace \ TrailheadBranchDemo \ build \ build.xml
属性:
diffDir=./deploy
scriptName=get_diff_branches
sf.deploy.serverurl=https://login.salesforce.com
sf.deploy.username=***********
sf.checkOnly=true
sf.pollWaitMillis=100000
sf.runAllTests=false
target=${GIT_BRANCH}
sf.maxPoll=100
sf.deploy.password=****************
sf.logType=None
targetName=master
get_diff_branches.sh:
#!/bin/bash
export LESSCHARSET=utf-8
targetBranch=$2
echo 'Starting git diff'
cd ..
echo 'Switching to origin/'$targetBranch
git checkout -f origin/$targetBranch
echo 'Merging target branch ('$1') into current branch (origin/'$targetBranch')'
git merge --no-commit --no-ff $1
echo 'Merged. Looking for conflicts'
git ls-files -u | awk '{$1=$2=$3=""; print $0}' | awk '{ sub(/^[ \t]+/, ""); print }' | sort -u > conflicts.txt
if [ -s conflicts.txt ]
then
echo 'Conflicts found. Please resolve conflicts prior validation...'
echo '============================================================='
echo -e '\n\nConflicting files:\n'
cat conflicts.txt
exit 1
else
echo 'Starting git diff'
git status -s > diff.txt
echo 'Git diff done.'
echo 'Clean double quotes'
sed -i 's/\"//g' diff.txt
echo 'Cleaned. Result:'
cat diff.txt
fi
我的build.xml文件包含以下内容:
<project name="ANT Jobs" basedir="." xmlns:sf="antlib:com.salesforce">
<tstamp>
<format property="BUILD_DATE"
pattern="yyyyMMdd" />
</tstamp>
<condition property="sf.deploy.username" value="">
<not>
<isset property="sf.deploy.username" />
</not>
</condition>
<condition property="sf.deploy.password" value="">
<not>
<isset property="sf.deploy.password" />
</not>
</condition>
<condition property="sf.deploy.sessionId" value="">
<not>
<isset property="sf.deploy.sessionId" />
</not>
</condition>
<taskdef resource="com/salesforce/antlib.xml" uri="antlib:com.salesforce">
<classpath>
<pathelement location="../migration_tool/ant-salesforce.jar" />
</classpath>
</taskdef>
<!-- ========================================== -->
<!-- Deployment targets -->
<!-- ========================================== -->
<target name="sf_prepare_deployment">
<echo message="START: Create diff dir" />
<echo message="Checking against targer: ${target}" />
<mkdir dir="../${diffDir}" />
<mkdir dir="../${diffDir}/src" />
<exec executable="C:\Program Files\Git\bin\bash.exe" osfamily="windows" failonerror="true">
<arg value="${scriptName}.sh" />
<arg value="${target}" />
<arg value="${targetName}" />
</exec>
<exec executable="/bin/bash" osfamily="unix" failonerror="true">
<arg value="${scriptName}.sh" />
<arg value="${target}" />
</exec>
<exec executable="C:\Program Files\Git\bin\bash.exe" osfamily="windows">
<arg value="create_changes.sh" />
<arg value="${diffDir}" />
</exec>
<exec executable="/bin/bash" osfamily="unix">
<arg value="create_changes.sh" />
<arg value="${diffDir}" />
</exec>
<echo message="Generating package.xml" />
<exec executable="C:\Program Files\Git\bin\bash.exe" osfamily="windows">
<arg value="generate_package.sh" />
<arg value="../final.txt" />
<arg value="package" />
<arg value="../${diffDir}/src" />
</exec>
<exec executable="/bin/bash" osfamily="unix">
<arg value="generate_package.sh" />
<arg value="../final.txt" />
<arg value="package" />
<arg value="../${diffDir}/src" />
</exec>
<echo message="Package generated." />
<echo message="Adding properties if applicable" />
<exec executable="C:\Program Files\Git\bin\bash.exe" osfamily="windows">
<arg value="properties_helper.sh" />
<arg value="${propsEnv}" />
<arg value="../${diffDir}/src" />
</exec>
<exec executable="/bin/bash" osfamily="unix">
<arg value="properties_helper.sh" />
<arg value="${propsEnv}" />
<arg value="../${diffDir}/src" />
</exec>
<echo message="Properties added. Finished." />
</target>
<target name="sf_prepare_full_deployment">
<echo message="START: Copying deployment files" />
<copy todir="../${diffDir}/src">
<fileset dir="../src" excludes="**/staticresources/**" />
</copy>
</target>
<target name="sf_build" depends="sf_prepare_deployment">
<echo message="START: SFDC Deployment" />
<echo message="../${diffDir}/src" />
<sf:deploy username="${sf.deploy.username}" password="${sf.deploy.password}"
serverurl="${sf.deploy.serverurl}" sessionId="${sf.deploy.sessionId}"
deployRoot="../${diffDir}/src" maxPoll="${sf.maxPoll}"
pollWaitMillis="${sf.pollWaitMillis}" checkOnly="${sf.checkOnly}"
runAllTests="${sf.runAllTests}" logType="${sf.logType}"
/>
</target>
<target name="sf_build_independent" depends="sf_prepare_full_deployment">
<echo message="Adding properties if applicable" />
<exec executable="/bin/bash" osfamily="unix">
<arg value="properties_helper.sh" />
<arg value="${propsEnv}" />
<arg value="../${diffDir}/src" />
</exec>
<echo message="Properties added. Finished." />
<echo message="START: SFDC Deployment" />
<echo message="../${diffDir}/src" />
<sf:deploy username="${sf.deploy.username}" password="${sf.deploy.password}"
serverurl="${sf.deploy.serverurl}" sessionId="${sf.deploy.sessionId}"
deployRoot="../${diffDir}/src" maxPoll="${sf.maxPoll}"
pollWaitMillis="${sf.pollWaitMillis}" checkOnly="${sf.checkOnly}"
runAllTests="${sf.runAllTests}" logType="${sf.logType}"
/>
</target>
<target name="git_tag">
<echo message="Build date is: ${BUILD_DATE}" />
<echo message="Build number: ${BUILD_NUMBER}" />
<echo message="Build tag name will be: ${ENV}_${BUILD_DATE}_${BUILD_NUMBER}" />
<echo message="Creating tag on current repository" />
<exec executable="/bin/bash" osfamily="unix">
<arg value="create_tag.sh" />
<arg value=".." />
<arg value="${ENV}_${BUILD_DATE}_${BUILD_NUMBER}" />
<arg value="${REPO_PASS}" />
</exec>
</target>
</project>
每当文件提交到git时,都会运行该构建,并调用ant目标:但是当它尝试合并两个分支以获取差异时,它将失败并抛出此错误:
**sf_prepare_deployment:**
[echo] START: Create diff dir
[echo] Checking against targer: origin/hotfix/test1
[exec] Starting git diff
[exec] Switching to origin/master
[exec] Previous HEAD position was 78d7196... savepoint 9
[exec] HEAD is now at d72b6e9... test commit 1
[exec] Merging target branch (origin/hotfix/test1) into current branch (origin/master)
[exec] Merged. Looking for conflicts
[exec] error: cannot stat 'build/get_diff_branches.sh': Permission denied
[exec] Starting git diff
[exec] Git diff done.
[exec] Clean double quotes
[exec] Cleaned. Result:
[exec] ?? build/
[exec] ?? conflicts.txt
[exec] ?? diff.txt
[exec] /usr/bin/bash: create_changes.sh: No such file or directory
[exec] Result: 127
[echo] Generating package.xml
[exec] /usr/bin/bash: generate_package.sh: No such file or directory
[exec] Result: 127
[echo] Package generated.
[echo] Adding properties if applicable
[exec] /usr/bin/bash: properties_helper.sh: No such file or directory
[exec] Result: 127
[echo] Properties added. Finished.
还无法识别properties_helper.sh和generate_package.sh。 有人在詹金斯遇到过这个问题吗?