Conditional Steps
Several questions about conditionals rolled into one here?
Is the a way to do any of the following within the same step without shelling out to the operating system?
1) Evaluation of multiple conditions within a step?
If A && B Then run command A
Else run command B
2) Multiple Ifs within the same step?
If A Then set variable1 = "A"
Else If B then variable1 = "B"
Else If C then variable1 = "C"
Else variable1 = ""
End if
2) Nested Ifs?
If variable1 == "" Then
if variable2 == "" Then
Fail Job
Else
Command B
End if
Else
if variable2 = "" Then
Command A
Else
Command C
End if
Thanks!
Is the a way to do any of the following within the same step without shelling out to the operating system?
1) Evaluation of multiple conditions within a step?
If A && B Then run command A
Else run command B
2) Multiple Ifs within the same step?
If A Then set variable1 = "A"
Else If B then variable1 = "B"
Else If C then variable1 = "C"
Else variable1 = ""
End if
2) Nested Ifs?
If variable1 == "" Then
if variable2 == "" Then
Fail Job
Else
Command B
End if
Else
if variable2 = "" Then
Command A
Else
Command C
End if
Thanks!
4 answers
Several questions about conditionals rolled into one here?
Is the a way to do any of the following within the same step without shelling out to the operating system?
1) Evaluation of multiple conditions within a step?
If A && B Then run command A
Else run command B
2) Multiple Ifs within the same step?
If A Then set variable1 = "A"
Else If B then variable1 = "B"
Else If C then variable1 = "C"
Else variable1 = ""
End if
2) Nested Ifs?
If variable1 == "" Then
if variable2 == "" Then
Fail Job
Else
Command B
End if
Else
if variable2 = "" Then
Command A
Else
Command C
End if
Thanks!
Hi Jonas,
Unfortunately, those are more advanced scenarios than the current conditional step logic can handle.
If you've got the time, you should check out the 2011 M4 Demo driver and its support of a 'JavaScript' step provider type.
https://jazz.net/downloads/rational-build-forge/milestones/2011M4
If you click on the link and choose the 'New & Noteworthy' tab it gives a description of the JavaScript step provider type. In short, it gives you the ability to use the JavaScript language within a Build Forge step.
The 2011 M4 Demo driver installation is very easy and has its own internal database that is already configured for the demo driver.
bju
In article <i68t3c>,
jonasgryder <jgryder> wrote:
Depending on what you mean by "set", you might not even be able to do
these without contortions, even if shelling out.
If "set" means "set shell variable", then it can be done via the
shell.
If "set" means "set BuildForge variable" ... assuming Windows CMD.exe
(the same problems arise in any other shell), if you try
If A (
.set env group "variable1=A"
) Else If B (
.set env group "variable1=B"
) Else If C (
.set env group "variable1=C"
) Else (
.set env group "variable1="
)
that doesn't work. The problem is that Build Forge breaks apart any
step at each dot command. Each contiguous block of shell commands are
run as separate scripts. So the first script it runs consists solely
of
If A (
which gives a syntax error (missing close paren). Then it runs
.set env group "variable1=A"
unconditionally. The result of the above would be five shell syntax
errors, and the last assignment will have effect unconditionally.
The only way you can do that in current Build Forge is along these
lines:
If A (
echo A>variable1.txt
) Else If B (
echo B>variable1.txt
) Else If C (
echo C>variable1.txt
) Else (
REM I *think* this will have the correct effect.
REM It will put one line ending into file variable1.txt,
REM which I think .set will strip out.
echo.>variable1.txt
)
.set env group "variable1=`type variable1.txt`"
Similarly for "fail" here. What I do is set the step to fail based on
filter, one of the patterns is "error ", and to fail the step I do
echo error - some informative message here
exit 1
The "exit" just stops it from running more steps; the echo is what
actually fails the step. If the step is set to fail on exit code,
I still do the same thing, but the "exit 1" is what fails it.
If you really want to do ".fail" accept no substitutes, I'm not sure
how to do it, except by doing a ".bset" using the techniques above
(temporary file used in ".bset ... `...`") and a separate step to do
the fail.
--
Tim McDaniel, tmcd@panix.com
jonasgryder <jgryder> wrote:
Is the a way to do any of the following within the same step without
shelling out to the operating system?
....
2) Multiple Ifs within the same step?
If A Then set variable1 = "A"
Else If B then variable1 = "B"
Else If C then variable1 = "C"
Else variable1 = ""
End if
Depending on what you mean by "set", you might not even be able to do
these without contortions, even if shelling out.
If A Then set variable1 = "A"
Else If B then variable1 = "B"
Else If C then variable1 = "C"
Else variable1 = ""
End if
If "set" means "set shell variable", then it can be done via the
shell.
If "set" means "set BuildForge variable" ... assuming Windows CMD.exe
(the same problems arise in any other shell), if you try
If A (
.set env group "variable1=A"
) Else If B (
.set env group "variable1=B"
) Else If C (
.set env group "variable1=C"
) Else (
.set env group "variable1="
)
that doesn't work. The problem is that Build Forge breaks apart any
step at each dot command. Each contiguous block of shell commands are
run as separate scripts. So the first script it runs consists solely
of
If A (
which gives a syntax error (missing close paren). Then it runs
.set env group "variable1=A"
unconditionally. The result of the above would be five shell syntax
errors, and the last assignment will have effect unconditionally.
The only way you can do that in current Build Forge is along these
lines:
If A (
echo A>variable1.txt
) Else If B (
echo B>variable1.txt
) Else If C (
echo C>variable1.txt
) Else (
REM I *think* this will have the correct effect.
REM It will put one line ending into file variable1.txt,
REM which I think .set will strip out.
echo.>variable1.txt
)
.set env group "variable1=`type variable1.txt`"
2) Nested Ifs?
If variable1 == "" Then
if variable2 == "" Then
Fail Job
Else
Command B
End if
Else
if variable2 = "" Then
Command A
Else
Command C
End if
Similarly for "fail" here. What I do is set the step to fail based on
filter, one of the patterns is "error ", and to fail the step I do
echo error - some informative message here
exit 1
The "exit" just stops it from running more steps; the echo is what
actually fails the step. If the step is set to fail on exit code,
I still do the same thing, but the "exit 1" is what fails it.
If you really want to do ".fail" accept no substitutes, I'm not sure
how to do it, except by doing a ".bset" using the techniques above
(temporary file used in ".bset ... `...`") and a separate step to do
the fail.
--
Tim McDaniel, tmcd@panix.com
Thanks Tim,
Yes, I've pretty much concluded that I'm doing a lot of convoluted shell work until the javascript engine is released, (and maybe even then, depending on what is accessible)
Here is the best way I've figured out to set a variable based on an if by shelling out in Linux. It's ugly, but it works.
.bset env "FocFilesSw=` if ; then echo "1"; else echo "0"; fi`"
By echoing back only a single value to the environment variable, I can populate it, or test multiples using the linux if. It does limit me to setting one variable at a time, but at least I can set it to different values based on a complex if.
Depending on what you mean by "set", you might not even be able to do
these without contortions, even if shelling out.
If "set" means "set shell variable", then it can be done via the
shell.
If "set" means "set BuildForge variable" ... assuming Windows CMD.exe
(the same problems arise in any other shell), if you try
If A (
.set env group "variable1=A"
) Else If B (
.set env group "variable1=B"
) Else If C (
.set env group "variable1=C"
) Else (
.set env group "variable1="
)
that doesn't work. The problem is that Build Forge breaks apart any
step at each dot command. Each contiguous block of shell commands are
run as separate scripts. So the first script it runs consists solely
of
If A (
which gives a syntax error (missing close paren). Then it runs
.set env group "variable1=A"
unconditionally. The result of the above would be five shell syntax
errors, and the last assignment will have effect unconditionally.
The only way you can do that in current Build Forge is along these
lines:
If A (
echo A>variable1.txt
) Else If B (
echo B>variable1.txt
) Else If C (
echo C>variable1.txt
) Else (
REM I *think* this will have the correct effect.
REM It will put one line ending into file variable1.txt,
REM which I think .set will strip out.
echo.>variable1.txt
)
.set env group "variable1=`type variable1.txt`"
Similarly for "fail" here. What I do is set the step to fail based on
filter, one of the patterns is "error ", and to fail the step I do
echo error - some informative message here
exit 1
The "exit" just stops it from running more steps; the echo is what
actually fails the step. If the step is set to fail on exit code,
I still do the same thing, but the "exit 1" is what fails it.
If you really want to do ".fail" accept no substitutes, I'm not sure
how to do it, except by doing a ".bset" using the techniques above
(temporary file used in ".bset ... `...`") and a separate step to do
the fail.
--
Tim McDaniel, tmcd@panix.com
Yes, I've pretty much concluded that I'm doing a lot of convoluted shell work until the javascript engine is released, (and maybe even then, depending on what is accessible)
Here is the best way I've figured out to set a variable based on an if by shelling out in Linux. It's ugly, but it works.
.bset env "FocFilesSw=` if ; then echo "1"; else echo "0"; fi`"
By echoing back only a single value to the environment variable, I can populate it, or test multiples using the linux if. It does limit me to setting one variable at a time, but at least I can set it to different values based on a complex if.
In article <i68t3c>,
jonasgryder <jgryder> wrote:
Is the a way to do any of the following within the same step without
shelling out to the operating system?
....
2) Multiple Ifs within the same step?
If A Then set variable1 = "A"
Else If B then variable1 = "B"
Else If C then variable1 = "C"
Else variable1 = ""
End if
Depending on what you mean by "set", you might not even be able to do
these without contortions, even if shelling out.
If A Then set variable1 = "A"
Else If B then variable1 = "B"
Else If C then variable1 = "C"
Else variable1 = ""
End if
If "set" means "set shell variable", then it can be done via the
shell.
If "set" means "set BuildForge variable" ... assuming Windows CMD.exe
(the same problems arise in any other shell), if you try
If A (
.set env group "variable1=A"
) Else If B (
.set env group "variable1=B"
) Else If C (
.set env group "variable1=C"
) Else (
.set env group "variable1="
)
that doesn't work. The problem is that Build Forge breaks apart any
step at each dot command. Each contiguous block of shell commands are
run as separate scripts. So the first script it runs consists solely
of
If A (
which gives a syntax error (missing close paren). Then it runs
.set env group "variable1=A"
unconditionally. The result of the above would be five shell syntax
errors, and the last assignment will have effect unconditionally.
The only way you can do that in current Build Forge is along these
lines:
If A (
echo A>variable1.txt
) Else If B (
echo B>variable1.txt
) Else If C (
echo C>variable1.txt
) Else (
REM I *think* this will have the correct effect.
REM It will put one line ending into file variable1.txt,
REM which I think .set will strip out.
echo.>variable1.txt
)
.set env group "variable1=`type variable1.txt`"
2) Nested Ifs?
If variable1 == "" Then
if variable2 == "" Then
Fail Job
Else
Command B
End if
Else
if variable2 = "" Then
Command A
Else
Command C
End if
Similarly for "fail" here. What I do is set the step to fail based on
filter, one of the patterns is "error ", and to fail the step I do
echo error - some informative message here
exit 1
The "exit" just stops it from running more steps; the echo is what
actually fails the step. If the step is set to fail on exit code,
I still do the same thing, but the "exit 1" is what fails it.
If you really want to do ".fail" accept no substitutes, I'm not sure
how to do it, except by doing a ".bset" using the techniques above
(temporary file used in ".bset ... `...`") and a separate step to do
the fail.
--
Tim McDaniel, tmcd@panix.com