Jenkinsfile 找不到命令 exec mv 命令
Jenkinsfile find command exec mv command not found
在 Jenkinsfile 中,我正在尝试从 find 命令移动文件:
steps {
sh "mkdir -p $WORKSPACE/rpmbuild/{SPECS,BUILD,SRPMS} $WORKSPACE/rpmbuild/RPMS/{noarch,x86_64} $WORKSPACE/rpmbuild/SOURCES/hello_world/"
sh "mv $WORKSPACE/hello_world.spec $WORKSPACE/rpmbuild/SPECS/"
script {
FOLDER_NAME = sh(returnStdout: true, script: 'echo $WORKSPACE | xargs basename')
}
sh "find $WORKSPACE/ -maxdepth 1 ! -name rpmbuild ! -name ${FOLDER_NAME} -exec mv {} rpmbuild/SOURCES/hello_world/ \;"
}
当我 运行 在 Jenkins 上构建时,我收到此错误消息:
[Pipeline] // script
[Pipeline] sh
+ find /home/jenkins/workspace/hello_world/ -maxdepth 1 '!' -name rpmbuild '!' -name hello_world
/home/jenkins/workspace/hello_world/html
/home/jenkins/workspace/hello_world/tests
/home/jenkins/workspace/hello_world/.git
/home/jenkins/workspace/hello_world/Jenkinsfile
/home/jenkins/workspace/hello_world/README.md
/home/jenkins/workspace/hello_world/CHANGELOG.txt
/home/jenkins/workspace/hello_world/.gitignore
/home/jenkins/workspace/hello_world/conf
+ -exec mv '{}' /home/jenkins/workspace/hello_world/rpmbuild/SOURCES/hello_world/ ';'
/home/jenkins/workspace/hello_world@tmp/durable-59cf8666/script.sh: line 2: -exec: command not found
[Pipeline] }
我很确定我没有以正确的方式做我想做的事,但如果有人可以帮助我解决我的问题或向我解释如何以更好的方式做到这一点,我会感激不尽
我通过修剪和使用三重双引号成功地使我的管道正常工作:
script {
// .trim() removes the EOL character at the end of the FOLDER_NAME variable.
FOLDER_NAME = sh(returnStdout: true, script: 'echo $WORKSPACE | xargs basename').trim()
}
// May be overkill to use the triple double-quote but works for me, so I keep it as is...
sh """
find $WORKSPACE/ -maxdepth 1 ! -name "$FOLDER_NAME" ! -name rpmbuild -exec mv {} $WORKSPACE/rpmbuild/SOURCES/hello_world/ \;
"""
在 Jenkinsfile 中,我正在尝试从 find 命令移动文件:
steps {
sh "mkdir -p $WORKSPACE/rpmbuild/{SPECS,BUILD,SRPMS} $WORKSPACE/rpmbuild/RPMS/{noarch,x86_64} $WORKSPACE/rpmbuild/SOURCES/hello_world/"
sh "mv $WORKSPACE/hello_world.spec $WORKSPACE/rpmbuild/SPECS/"
script {
FOLDER_NAME = sh(returnStdout: true, script: 'echo $WORKSPACE | xargs basename')
}
sh "find $WORKSPACE/ -maxdepth 1 ! -name rpmbuild ! -name ${FOLDER_NAME} -exec mv {} rpmbuild/SOURCES/hello_world/ \;"
}
当我 运行 在 Jenkins 上构建时,我收到此错误消息:
[Pipeline] // script
[Pipeline] sh
+ find /home/jenkins/workspace/hello_world/ -maxdepth 1 '!' -name rpmbuild '!' -name hello_world
/home/jenkins/workspace/hello_world/html
/home/jenkins/workspace/hello_world/tests
/home/jenkins/workspace/hello_world/.git
/home/jenkins/workspace/hello_world/Jenkinsfile
/home/jenkins/workspace/hello_world/README.md
/home/jenkins/workspace/hello_world/CHANGELOG.txt
/home/jenkins/workspace/hello_world/.gitignore
/home/jenkins/workspace/hello_world/conf
+ -exec mv '{}' /home/jenkins/workspace/hello_world/rpmbuild/SOURCES/hello_world/ ';'
/home/jenkins/workspace/hello_world@tmp/durable-59cf8666/script.sh: line 2: -exec: command not found
[Pipeline] }
我很确定我没有以正确的方式做我想做的事,但如果有人可以帮助我解决我的问题或向我解释如何以更好的方式做到这一点,我会感激不尽
我通过修剪和使用三重双引号成功地使我的管道正常工作:
script {
// .trim() removes the EOL character at the end of the FOLDER_NAME variable.
FOLDER_NAME = sh(returnStdout: true, script: 'echo $WORKSPACE | xargs basename').trim()
}
// May be overkill to use the triple double-quote but works for me, so I keep it as is...
sh """
find $WORKSPACE/ -maxdepth 1 ! -name "$FOLDER_NAME" ! -name rpmbuild -exec mv {} $WORKSPACE/rpmbuild/SOURCES/hello_world/ \;
"""