Use another variable value as variable value - octopus-deploy

I have variables in several projects that are substitutes the original config file value.
For instance, in project X the config key is smtpServ, and in project Y it's smtp.
I'd like to have 1 variable in a library set named smtpServer that should enter into smtpServ (project X) and smtp (project Y), so that I can keep it in 1 place.
Is this doable in the "Project Variables" view? (/projects/service-name/variables), or do I need to do it with a PS script?

You can reference the library variable value in your project-specific variables.
For example, in project X, you can create a variable named smtpServ that has a value of #{smtpServer}. In project Y, you can create a variable named smtp that has a value of #{smtpServer}.
Then you can update the value of smtpServer once instead of N number of times.
I will add a note of caution here that with generic names like this, there is a chance for a collision between the names. Say that project Z already has a variable named smtpServer. In this case, you can't use the value #{smtpServer} because it would be an infinite loop. Likewise, if any other variable referenced smtpServer, it will use the project value and not the library set variable. The solution here could be to delete the smtpServer variable from the project.
I prefer to give my variable names a prefix if possible. I may name the library variable global.smtpServer and reference it as #{global.smtpServer} to make a collision less likely.

Related

Colons in variables

Colons can be used as part of a variable name in Perl 6, together with angle brackets. These are apparently called extended identifiers, and are used to define things such as infix:<+>.
my $foo:bar = 3;
my $foo:bar<2> = 2;
my $foo:bar<baz> = 'quux';
say $foo:bar; # 3
say $foo:bar<2>; # 2 (and so on)
This creates identifiers with the same name in the current scope
say MY::.keys;
Prints ($=pod $_ $/ $buz !UNIT_MARKER $=finish EXPORT $foo:bar<2> $foo:bar<baz> $! ::?PACKAGE GLOBALish $bur::quux $ยข $foo:bar $?PACKAGE
But here's the thing.
say $foo:bar.kv; # prints key-value pairs.
print (0 3). So these coloned variables are creating a key-value pair. However, the other two "keys" (2 and baz) are not included in that set of key-value pairs. And if we really try to do say $foo:bar{'0'} or say $foo:bar<0>; we will obtain different errors, so there does not seem to be an actual way of using that as a real key. So I guess there are at least a couple of questions here:
Are these key-value pairs "real", or simply an unintended effect of something completely different?
If it is, can you define other values? Why are not the other "keys" included in that set?
Is there any user-facing way of getting all "angled" keys defined for a particular extended identifier? For instance, a way of obtaining all infix variables?
So these coloned variables are creating a key-value pair.
No, .kv (or kv) is producing the key-value pair:
my $foo = 3;
say kv $foo # (0 3)
When you call .kv on a list you get a list of indexes each followed by the associated value.
And every singular value will be treated as a list containing one value when you call a listy method on it.
Basically these are the same:
$foo:bar.kv
$foo:bar.list.kv

Increment on RobotFramework

I'm trying to run a FOR loop on robot framework depending of the status of another variable.
${STATUS1}= Run Keyword And Return Status Should Be Equal As Strings ${CELLVALUE} ${EXPECTEDVALUE}
\ ${COUNT}= Set Variable If '${STATUS1}' == 'True' ${COUNT}+1
\ ... '${STATUS1}' == 'False' ${COUNT}+0
But all I get is '''0'+0'+0'+1 or similar, even if I use Run keyword If and Evaluate instead of set var, I tried to convert to integer but nothing happens and I cannot convert it to integer or number. Any suggestions? thanks in advance!
It looks like you're simply wanting to increment ${COUNT} if ${CELLVALUE} equals ${EXPECTEDVALUE}. That can be done pretty easily with Set Variable if
If you know that ${CELLVALUE} and ${EXPECTEDVALUE} are of the same internal type (eg: strings or ints), and you're using robot framework 2.9 or greater, you can write it like this:
${COUNT}= Set variable if $CELLVALUE == $EXPECTEDVALUE
... ${COUNT+1} ${COUNT}
This assumes that ${COUNT} is initialized to an integer value, which you can do by assigning it the value ${0}
If you don't know the type, can't guarantee the type, or are using an older version of robot, you can use triple-quoted strings to coerce the values to strings:
${COUNT}= Set variable if '''${CELLVALUE}''' == '''${EXPECTEDVALUE}'''
... ${COUNT+1} ${COUNT}
Of course, you could use Run Keyword and Return Status like in your example, and then compare the status. That seems like an unnecessary extra step, but it might make sense in your actual test.
The point being, you can use Set variable if and extended variable syntax to solve this problem.
Note 1: With Set variable if, two values are provided. The first value is assigned if the expression is true, the second one is assigned if the value is false. The second value is the original variable, meaning it won't be changed. If you don't provide the second value, the variable will be set to None.
Note 2: Putting an expression inside curly braces (eg: ${COUNT+1} is documented in rule 4 of extended variable syntax.
Note 3: Starting with robot framework 2.9, variables are available in the evaluation namespace with the simplified syntax $varname. So, the robot variable ${CELLVALUE} can be used in python expressions as $CELLVALUE. This is documented in the section Evaluating Expressions in the BuiltIn library documentation.

Is it possible to have 2 variables point to the same address in memory

Is it possible in Visual Foxpro to have 2 variables that point to the same address in memory. Such that if the value of one of the variables is changed then the other is also changed. I understand that when passing arguments to functions they can be passed by value or reference but I want to know if this is possible in straight code. I think in other languages such as C this is called a pointer but I don't believe VFP has pointers. So if one writes the following code it will output the number 4.
a=4
b=a
a=6
? b && answer 4
But could one write code such as the following where the answer could be 6?
a=4
b=*a && note the inclusion of the asterisk (pointer?) here which won't compile in VFP
a=6
? b
No. There are no pointers or references in Foxpro; as you note, the closest thing to it is passing parameters by reference to functions. You might be able to try to kludge something together (as Jerry mentions) with objects using Access/Assign methods, but even then, all that gets passed to the Assign method is the value being assigned - nothing about whether it was originally another variable, a literal value, an object's property, etc.
You could simulate it by using an array or a table. The variables would contain only the array index or record number (or other index) as a reference, and you'd have to get the actual value from the array or table.
Take a look at the Visual Foxpro Access and Assign Methods. These methods can be used to execute code when querying a property or trying to change the value of a property. Below is a link that shows an example:
Access and Assign Example
You could do something like this:
a=4
b='a'
a=6
?&b

How do I use a predefined variable/constant in my Cucumber testing Scenario

I have defined a variable as userid in env.rb.
userid='1234'
In my Cucumber testing, Scenario, I wish to confirm that my response contains the correct userid. However, I do not wish to hard code the same in my Senario or step definition. Is it possible to do so?
I would place an additional file, let's say test_constanst.rb in the features/ dir. There, I would define a module like this:
module TestConstants
def self.user_id
1234
end
end
Like this, you have it separated from test configuration and code. You would just have to requrire the file from env.rb.
Variable scope in Ruby is controlled by sigils to some degree. Variables starting with $ are global, variables with # are instance variables, ## means class variables, and names starting with a capital letter are constants. Make the variable global and it will be available everywhere, i.e
$userid='1234'

Setting a watch point in GDB

I am operating a huge code base and want to monitor a value of a particular variable (which is buried deep down inside one of the files)especially when it gets set to zero.
1) Variable does not belong to global scope .Is there a better option than to first set breakpoint into the function where it is defined and then set the watch point?
2) After trying the option in 1 I see that watch point gets deleted after a while saying its out of frame which used this .This way it adds to the tediousness of the procedure since I have to add it again and again?Any workarounds?
3) Is there a way to check ie watch if a particular variable is equal to 0( or any specific constant)?
want to monitor a value of a particular variable
Often this is not the best approach, especially in large codebases.
What you really likely want to do is understand the invariants, and assert that they are true on entry and exit to various parts of the code.
1) Variable does not belong to global scope .Is there a better option than to first set breakpoint into the function where it is defined and then set the watch point?
No. For automatic (stack) variables you have to be in the scope where the variable is "active".
What you can do is set a breakpoint on some line, and attach commands to that breakpoint that will set the watchpoint automatically, e.g.
(gdb) break foo.c:123
(gdb) commands 1
silent
watch some_local
continue
end
3) Is there a way to check ie watch if a particular variable is equal to 0
You can't do that with a watchpoint, but you can with a conditional breakpoint:
(gdb) break foo.c:234 if some_local == 0
I will assume that you are using Linux. You can try this:
The first step is to make the variable static, like:
static int myVar;
Then, after compiling your code using -ggdb, you must discover the address of the variable inside your binary, like so (I have used a real case as example):
readelf -s pdv | grep tmp | c++filt
In my situation, the output is:
47: 081c1474 4 OBJECT LOCAL DEFAULT 25 startProc(int)::tmp
The address in this case is 081c1474. Now you can set a watch point inside GDB:
watch *0x081c1474
Mind the "*0x" before the correct address.
I know this question is old, but I hope it helps anyway.

Resources