TFS: Deploy same application to multiple geographic sites - tfs

Using TFS I want to deploy the same web application to two different locations (West,Central). For this, I am trying to run phases concurrently to both locations using the Run on multiple agents in parallel option.
The following sample contains only one step Deploy Website files
Here my question.
How can I provide a different value for the $(WebsiteServer) variable based on the multiplier?
I have tried to configure multiple variables in the environment.
And then use them like $($(Location).WebsiteServer)) but that does not expand correctly.
I am thinking now on creating a custom task that will create variables at release time base on the hardcoded values and use those variables instead. But it seems hacky.
Is there a better way to solve this?

Make WebsiteServer your multiplier, then make the value a comma-separated list of the servers.

You could add some variables as followed.
WebsiteServer, User and Pass variables are some intermediate variables to store your WebsiteServer IP, User Name and Password.
You could configure your environment as followed.
You could add a PowerShell Task to modify the values of WebsiteServer, User and Pass variables by logging command "##vso[task.setvariable variable=variableName]variableValueā€¯ from nested varialbes, such as $($(Location).WebsiteServer).
You could refer to the following powershell script:
Script:
Write-Host "##vso[task.setvariable variable=WebsiteServer]$($(Location).WebsiteServer)"
Write-Host "##vso[task.setvariable variable=User]$($(Location).User)"
Write-Host "##vso[task.setvariable variable=Pass]$($(Location).Pass)"
You could use WebsiteServer, User and Pass variables in Copy files Task like the following.

Related

Jenkins: Pass environment variable to the job parameter

Since I have the same static rarely changed parameters used by several jobs I decided to put it somewhere in one place of my Jenkins and use it across jobs.
The first thought that came to my mind was to move my 'static data' to the environment variables and get it using Active choice reactive parameter plugin which allows running simple groovy scripts on the job parameters page.
Please note that I know how to get environment parameters in the pipeline, but I do really need to have this data on the build with parameters screen, e.g. once I clicked build with parameters - I need my groovy code inside Active choice reactive parameter was able to read this environment variable and display as a parameter to the user.
A simple example of this need:
The environment variable contains the list of servers, the job is going to perform deployment of the application to the selected server. In this case, I want to be able to write something like this in the groovy script section of Active choice reactive parameter:
return[${env.SERVERS_LIST}]
Unfortunately the example above doesn't work. I wasn't able to find any working solution for this yet.
Well, after a few more tries I finally found a solution.
Instead of trying to read the environment variable in the pipeline manner the simple
return [SERVERS_LIST]
works perfect

How to select password from dropdown and pass it as parameter to jenkins job?

I have a problem. I use Jenkins to deploy application on machines. Depending on which machine i want to deploy new version I need to use different database passwords to run db migrations. I want to store credentials in Jenkins and for each deploy job select credentials set from dropdown which will be passed (just password ) to powershell script. I have Credentials Binding Plugin and Extended Choice Parameter Plugin. I thought it might help me with my problem, but I cannot find solution for this. Do you have any ideas how to achieve this?
As I understand, you need only to do two things:
add Credential Parameter in This project is parameterized section for possibility to select credentials set from dropdown.
enable Use secret text(s) or file(s) option in Build Environment section. This will allow you to take credentials of various sorts and use them from shell build steps and the like. Each binding will define an environment variable.
If you have already created Jenkins credentials like these:
then you will be available to run your job using Build with Parameters button and select needed credentials:
So, after configuring, you don't need to dig in job configuration each time, all possible credentials will be automatically loaded, you need only select the needed one when run a job.

How to update a Jenkins Properties Global Environment Variable from within a pipeline stage in Jenkinsfile

Wanting to update a ".env" properties value, so that the next execution has a new value.
loggingUtils.info("${env.testVar}")
env.testVar = "cat"
loggingUtils.info("${env.testVar}")
Currently what happens is if I configure the "env.testVar" to have a value of "dog" from within jenkins the print statements will be:
dog
cat
but the next time I execute I want it to be
cat
cat
However, it is always just
dog
cat
Is there a way to achieve setting the environment variables so that future builds will have the new variable? I would prefer to do this without a plugin if possible
Builds (can be thought of as "instances of executions") in Jenkins are independent of each other.
If you are trying to tie builds together by transmuting information across builds I would encourage you to think about what you are really trying to do and suggest you might not doing Continuous Integration properly.
Each time you execute a build it starts from scratch. Continuous Integration always starts with what's in source control. Nothing derived should be committed to source control.
I would suggest environment configuration should normally by stored in config files in source control and applied as appropriate via parameters to a build. (i.e what environment do I want to deploy a given build to?).

TFS integration - how to set environment variables accessible from test code

I'm writing a TFS / VSTS integration with our server by using extension.
I want to present extra data after the build, specifically I want to show an IFRAME and navigate to our server, to a specific URL, determined in part by a dynamically generated unique string.
I have the function that generates the string, but I need to set it as an environment variable before the tests start to run. This is important because the tests need to create that string on the server.
I searched the documentation, examples and other places, but couldn't find a complete example that sets a dynamically generated environment variable and then runs tests.
How do I do it?
You can add/set an environment variable through Logging Commands (e.g. PS: Write-Host "##vso[task.setvariable variable=testvar;]testvalue"), then the following tasks can get this variable as general variable.
With Logging Commands, you also can add additional information in build summary. (##vso[task.uploadsummary]local file path)
You also can deploy a build result extension to display additional information. vsts-extension-samples

Get result of a build step in Hudson/Jenkins to re-use it in another one

My question may be silly but I've been trying several ways and I still can't do what I want, i.e.:
use the scp target of Ant to target a remote machine and execute
a script there
this script creates a dynamic list of files
get this list of files (only their names) back in Hudson to use it in the next build step (another scp from Ant)
I tried to use environment variables but they are interpreted by Hudson so I'm stuck here...
Globally my question would be: how to get a result from an Ant build step ?
Thanks for your ideas,
Emmanuel
You may find File parameter useful. This allows you to create an input file, pass it to build. You may need to write script/ant script to process the file though.
In the long term you may evaluate a Hudson farm. This will allow to create tasks that span multiple machines , pass results around. (https://wiki.jenkins-ci.org/display/JENKINS/Plugins)
You can get the ID(s) of the job that triggered your job via the API and fetch their status.

Resources