首页 > 解决方案 > 脚本在 Windows 中运行,但在 Jenkins 中失败

问题描述

我有一个 bash 脚本:

C:/Jenkins/workspace/xmlstarlet-1.6.1-win32/xmlstarlet-1.6.1/xml.exe ed -L -s "/Package/types[name='$TYPENAME']" -t elem -n members -v "$ENTITY" $SCRIPTFILE

C:/Jenkins/workspace/xmlstarlet-1.6.1-win32/xmlstarlet-1.6.1/xml.exe ed -L -s "/Package" -t elem -n types -v "" $SCRIPTFILE

它在 xml 中插入特定类型的节点,这在本地运行良好,但是当尝试通过任何脚本运行时,它会失败:

蚂蚁脚本:

    <exec executable="C:\Program Files\Git\bin\bash.exe" osfamily="windows">
        <arg value="generate_package.sh" />
        <arg value="C:/Jenkins/workspace/TrailheadBranchDemo/final.txt" />
        <arg value="package" />
        <arg value="C:/Jenkins/workspace/deploy/src" />
    </exec>

错误消息:无效的表达式:C:/Program Files/Git/Package

它无法选择/Packageor/Package/types[not(*)]表达式。

标签: bashant

解决方案


问题是:

在 Windows 上,bash 脚本的工作方式如下:

$ C:/Jenkins/workspace/xmlstarlet/xmlstarlet/xml.exe ed -L -i "Package" -t attr -n xmlns -v "http://soap.sforce.com/2006/04/metadata" C:/Jenkins/workspace/deploy/src/package.xml

而不是这个:

$ C:/Jenkins/workspace/xmlstarlet/xmlstarlet/xml.exe ed -L -i '/Package' -t attr -n xmlns -v "http://soap.sforce.com/2006/04/metadata" C:/Jenkins/workspace/deploy/src/package.xml

/PackageWindows 中不能很好地识别。


推荐阅读