小编Foo*_*aut的帖子

从jenkins groovy脚本中的bash脚本捕获退出代码

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)

bash exit jenkins jenkins-groovy jenkins-pipeline

4
推荐指数
1
解决办法
6347
查看次数

标签 统计

bash ×1

exit ×1

jenkins ×1

jenkins-groovy ×1

jenkins-pipeline ×1