copy_file.sh从Jenkins Groovy脚本执行bash脚本,并尝试根据bash脚本生成的退出代码来发送邮件。
copy_file.sh:
#!/bin/bash
$dir_1=/some/path
$dir_2=/some/other/path
if [ ! -d $dir ]; then
echo "Directory $dir does not exist"
exit 1
else
cp $dir_2/file.txt $dir_1
if [ $? -eq 0 ]; then
echo "File copied successfully"
else
echo "File copy failed"
exit 1
fi
fi
Run Code Online (Sandbox Code Playgroud)
的部分groovy script:
stage("Copy file") {
def rc = sh(script: "copy_file.sh", returnStatus: true)
echo "Return value of copy_file.sh: ${rc}"
if (rc != 0)
{
mail body: 'Failed!',
subject: 'File copy failed',
to: …Run Code Online (Sandbox Code Playgroud)