BuildForge获取Linux shell命令执行的返回值
在buildforge中如何获取Linux shell运行的return code例子:perl test.pl -optionchmod 777 some_fileln some_file current_link以以上三个命令作为例子,如果这三个命令不加任何处理写在build
·
在buildforge中如何获取Linux shell运行的return code
例子:
perl test.pl -option
chmod 777 some_file
ln some_file current_link
以以上三个命令作为例子,如果这三个命令不加任何处理写在build forge的step中,build forge总是以最后一跳命令的返回值最为最后的返回值。
由于buildforge的servr可能安装不同的bash,以hash/ksh为例:
有两种方法来获取return code
1Add multiple dollar signs($) to a variable so to get past the various preparsers. We have found that in most cases it takes four(4) $$$$?.
perl test.pl -option
if [ 0 -eq $$$$? ] ; then
echo "(I)script.pl was successful"
else
echo "(E)test.pl failed"
exit 2
fi
chmod 777 some_file
if [ 0 -eq $$$$? ] ; then
echo "(I)chmod was successful"
else
echo "(E)chmod failed"
exit 2
fi
ln some_file current_link
# Since this is the last command you would not have to check the return code as BuildForge will, but we will anyway
if [ 0 -eq $$$$? ] ; then
echo "(I)Link was successful"
else
echo "(E)Link failed"
exit 2
fi
2Set the _NO_PREPARSE_COMMAND variable to 1 for a project or a step
关于:
_NO_PREPARSE_COMMAND
The system normally attempts to resolve the values of environment variables before sending commands to agents. When the _NO_PREPARSE_COMMAND variable is defined (with any value), the system sends variables to agents without resolving them. Use this variable to ensure that your operating system shell handles the variables.
例子:
.tset env "_NO_PREPARSE_COMMAND=1"
perl test.pl -option
if [ 0 -eq $? ] ; then
echo "(I)test.pl was successful"
else
echo "(E)test.pl failed"
exit 2
fi
chmod 777 some_file
if [ 0 -eq $? ] ; then
echo "(I)chmod was successful"
else
echo "(E)chmod failed"
exit 2
fi
ln some_file current_link
# Since this is the last command you would not have to check the return code as BuildForge will, but we will anyway
if [ 0 -eq $? ] ; then
echo "(I)Link was successful"
else
echo "(E)Link failed"
exit 2
fi
补充一些相关的知识:
http://publib.boulder.ibm.com/infocenter/bldforge/v7r1m2/index.jsp?topic=/com.ibm.rational.buildforge.doc/topics/env_var_interpretation.html
首先:如何在step中定义变量
支持unix风格和windows风格的变量语法
windows风格的如:
set a=100
echo %a%
unix或者linux风格的如:
f=200
echo $f
.tset命令:用来临时改变设置,仅仅在当前步骤中生效。语法.tset env "<VariableName>=<DesiredValue>" [...]
However, threading can affect this behavior. Example:
1. A step is threaded and it specifies an Inline.
2. The first step of the Inline is also threaded.
注意以上两句,不过我还没来及研究
.bset:范围更大,对当前job有效
.bset env "VAR1=VALUE1"
.bset env "VAR2=$VAR1"
如果对一个变量有多个.bset,总是以最后一个运行的有效
例子:
perl test.pl -option
chmod 777 some_file
ln some_file current_link
以以上三个命令作为例子,如果这三个命令不加任何处理写在build forge的step中,build forge总是以最后一跳命令的返回值最为最后的返回值。
由于buildforge的servr可能安装不同的bash,以hash/ksh为例:
有两种方法来获取return code
1Add multiple dollar signs($) to a variable so to get past the various preparsers. We have found that in most cases it takes four(4) $$$$?.
perl test.pl -option
if [ 0 -eq $$$$? ] ; then
echo "(I)script.pl was successful"
else
echo "(E)test.pl failed"
exit 2
fi
chmod 777 some_file
if [ 0 -eq $$$$? ] ; then
echo "(I)chmod was successful"
else
echo "(E)chmod failed"
exit 2
fi
ln some_file current_link
# Since this is the last command you would not have to check the return code as BuildForge will, but we will anyway
if [ 0 -eq $$$$? ] ; then
echo "(I)Link was successful"
else
echo "(E)Link failed"
exit 2
fi
2Set the _NO_PREPARSE_COMMAND variable to 1 for a project or a step
关于:
_NO_PREPARSE_COMMAND
The system normally attempts to resolve the values of environment variables before sending commands to agents. When the _NO_PREPARSE_COMMAND variable is defined (with any value), the system sends variables to agents without resolving them. Use this variable to ensure that your operating system shell handles the variables.
例子:
.tset env "_NO_PREPARSE_COMMAND=1"
perl test.pl -option
if [ 0 -eq $? ] ; then
echo "(I)test.pl was successful"
else
echo "(E)test.pl failed"
exit 2
fi
chmod 777 some_file
if [ 0 -eq $? ] ; then
echo "(I)chmod was successful"
else
echo "(E)chmod failed"
exit 2
fi
ln some_file current_link
# Since this is the last command you would not have to check the return code as BuildForge will, but we will anyway
if [ 0 -eq $? ] ; then
echo "(I)Link was successful"
else
echo "(E)Link failed"
exit 2
fi
补充一些相关的知识:
http://publib.boulder.ibm.com/infocenter/bldforge/v7r1m2/index.jsp?topic=/com.ibm.rational.buildforge.doc/topics/env_var_interpretation.html
首先:如何在step中定义变量
支持unix风格和windows风格的变量语法
windows风格的如:
set a=100
echo %a%
unix或者linux风格的如:
f=200
echo $f
.tset命令:用来临时改变设置,仅仅在当前步骤中生效。语法.tset env "<VariableName>=<DesiredValue>" [...]
However, threading can affect this behavior. Example:
1. A step is threaded and it specifies an Inline.
2. The first step of the Inline is also threaded.
注意以上两句,不过我还没来及研究
.bset:范围更大,对当前job有效
.bset env "VAR1=VALUE1"
.bset env "VAR2=$VAR1"
如果对一个变量有多个.bset,总是以最后一个运行的有效
更多推荐
已为社区贡献5条内容
所有评论(0)