VSTS Label Sources not reading Build Phase Output Variable - tfs

I'm trying to tag a build using the built-in, tag sources functionality of team foundation server, the tag is created during the build phase and outputted as an output variable. However the label sources step never evaluates the variable and the step fails. Why does the label sources step not evaluate the value of the tag variable ?
Tag sources has been setup like this
The Tag step creates and outputs the tag
Both the "Tag Step Logs" and the "PRINT ENV VARS" show the value of the variable that is created.
The label sources then fails as it's not able to read the tag value from the variable

A solution to the issue has been found.
I am updating the variable Build.BuildNumber and using this in the Tag sources. This is working as this variable is available to the label sources step.
I added the following line, to update the build variable
Write-Host ("##vso[build.updatebuildnumber]$tag")
This updated number is then accessed by the label sources step using the variable
$(Build.BuildNumber)
Thanks Alexey, for figuring this out.

That is because the Output Variable is only available in the next session, that means it only can be read from the steps which behind the step Tag variable creates.
But as you can see, the Label source is in the fist Get sources step, it's before the step Tag variable creates.
So, the Output Variable can not be read. We can not label sources with the customized variable.
We can only use the predefined and user defined variables on the variables tab to Label sources. See Label sources for details.

Related

TFS Build 2015 - using custom variables in label format

TFS Build allows to define a label format in "repository" tab in build definition. I can define custom variables in "variables" tab and use them in label format definition. But is there any possibility to change a value of such custom variable in batch script in custom build step? Or maybe in some other type of a build step? I can get a value of such variable in a batch script, but any changes are ignored (though "Modify Environment" checkbox is set). Is there any possibility to use a value calculated during a build process as a part of a label format?
Thanks in advance!
It should be. There is no much difference with the custom variable in "variables" tab and custom variable in batch script in custom build step.
However, please note not every custom variable can be used as a part of a lable format. Please double check this.
Some build variables might yield a value that is not a valid label.
For example variables such as $(Build.RequestedFor) and
Build.DefinitionName can contain white space. If the value contains
white space, the tag is not created.
Update from OP: As a workaround, with build.updatebuildnumber you could update a build number and then use $(build.buildNumber) in label format.

Cannot receive parameter from Script content to Predefined Parameter in Jenkins

I would like to pass hostname parameter which is declared at Script Content to Predefined Parameter in Trigger/calls on build other project where my child project will receive parameter from the parent project.My code looks like this in Script Content:
`machine_name="$(hostname)"`
So in order to pass my parameter to the child project I declared:
host_name=${machinename}
in Script Content .But when I check in my child project it display as ${machinename} which is not I want .Can someone tell me what am I missing or what step that I done wrong or is there any way to perform this ?
Try using ENv Inject plugin, all you need to do is below:
Your script should contain below step:
machine_name="$(hostname)" > inject.txt
Now use Inject environment variables build step and in
property file path give inject.txt
what's the use?
By this step, now you machine_name variable holds the hostname value throughout the job.
Next, in your Parameter in Trigger/calls on build other project
host_name=${machine_name}
And use the same variable in child job.
I think there is no need for multiple assignments above, but still you can try this.
'_' was missing. host_name=$machine_name.
you cannot set or pass the parameter value from the script o/p. either make it as env variable using groovy or set in to property file & read.

How to change a tfs build variable in script

I'm using TFS2015 update 1. I want to pass information from one build step to the next, how is this possible?
That seems like a very simple task, but I can't figure out how that's suppose to work. Passing a variable to a build step is easy, but passing information from one step to the next seems to be impossible. I hope I'm wrong.
You can call the task.setvariable Logging Command, which sets a variable in the variable service of taskcontext. The first task can set a variable, and following tasks are able to use the variable. The variable is exposed to the following tasks as an environment variable.
Example:
##vso[task.setvariable variable=testvar;]testvalue

i want to make generic parameters in jenkins

How can I make generic parameters in jenkins that will be updated automatically for example I want to be able to create a parameter which hold today's date and it will be update automatically and not manually ?
thanks!
You might want to use EnvInject.
Setup your job and then add a build step "Inject envornment variables" from a file with an absolute path or the path relative to current job's workspace, which will contain something like:
DATE_VARIABLE="20150708"
OTHER_OPTIONAL_VARIABLE="value"
In previous execute shell step you may for example do:
echo "DATE_VARIABLE="`date +"%d%m%Y"` > env_inject.txt
After all that you don't need Parameters for a build, since you will have the needed parameter injected as an environment variable.

Updating the Jenkins Variable with a value calculated in a batch file

I am new to Jenkins. My aim is to define a build job in which I have created an environment variable suppose "x" by checking "This build is parameterized" option. I am executing a batch file which is performing a set of instructions and I want the x to be updated by a value calculated in batch file. Any suggestions how can I update the Jenkins variable value calculated using a batch file. I have tried using enviject plugin but not getting how to update the variable.
Thanks in advance
enviject plugin should be helpful here.
But - you need to update your batchfile to create a property file.
As the first step in the build action, I am passing some properties to my test.
Then, I use the property name like a parameter passed to Jenkins to execute a windows batch command. This bat file creates a result file in .properties format.
As the third step, i read the (result) property file. The result property file can have the same properties with updated values.
Now - your original proeprties would have been updated with new values & can be used in your subsequent build steps.

Resources