I am trying to set new environment variables in InvokeProcess in tfs2010, I tried creating a variable ENV_VAR of type IDictionary() and then in InvokeProcess then I tried adding new variable as ENV_VAR.Add("New","Variable") but it shows me an error.
Thanks
/G
For someone with similar issue , I managed to resolve it , Way to define EnvironmentVariable in InvokeProcess activity
New Dictionary(Of String, String) From {{"Key1", "Value1"}, {"key2", "value2"}}
Related
I have a Source DacPac and a Target DacPac. With powershell I would like to compare both and generate a upgrade script. This per se is simple for all cases with DacServices as long as there is a valid Connection String. However, for my CD pipeline, I do not know the eventual connection string nor do I wish to know. And all I want is for the script to generate the SQL.
I tried this out with sqlpackage.exe by sending args as follows
$args = #(
"/a:Script",
"/sf:$PathToDacpacSource",
"/tf:$PathToDacpacTarget",
"/op:$outputFile",
"/tdn:$TargetDatabaseName"
)
and this works fine. so far I had managed by adding just a dependency to DacServices via [Microsoft.SqlServer.DacFx.x64], but this inability to generate scripts without a connection string has forced me to add the dependency on SQLPackage.exe via [Microsoft.Data.Tools.Msbuild] too
The constructors for DacServices all require a ConnectionString
Has anyone else encountered a similar situation and any solutions?
or Do you exclusively use SQLPackage at the deployment side to overcome this issue?
There is a static version of GenerateDeployScript that does not need a connection string as you don't call the constructor for a static method, it isn't very clear in the msdn documentation but the "S" which looks like it is floating means it is static :)
https://msdn.microsoft.com/en-us/library/microsoft.sqlserver.dac.dacservices.generatedeployscript(v=sql.120).aspx#M:Microsoft.SqlServer.Dac.DacServices.GenerateDeployScript%28Microsoft.SqlServer.Dac.DacPackage,Microsoft.SqlServer.Dac.DacPackage,System.String,Microsoft.SqlServer.Dac.DacDeployOptions%29
` public static string GenerateDeployScript( DacPackage sourcePackage, DacPackage targetPackage, string targetDatabaseName, DacDeployOptions options = null )
In previous versions of TFS (before 2015), there was a build environment variable for PowerShell called: TF_BUILD_DROPLOCATION, which gave the The location of the drop:
https://msdn.microsoft.com/library/hh850448%28v=vs.120%29.aspx.
I can't find the equivalent variable in TFS 2017.
What is the best practice to get it?
With Build agent tasks taking over things are different. What I do to see the various build environment variables is to make a simple batch file containing this:
SET C:\temp\EnvVars.txt
That'll produce a quick list of what is available.
Here's what I see with the TFS 2017 build agent:
agent.jobstatus=Succeeded
AGENT_BUILDDIRECTORY=C:\Agent\_work\2
AGENT_HOMEDIRECTORY=C:\Agent
AGENT_ID=2 AGENT_JOBNAME=Build
AGENT_JOBSTATUS=Succeeded
AGENT_MACHINENAME=BUILDMACHINE
AGENT_NAME=BUILDMACHINE
AGENT_OS=Windows_NT
AGENT_ROOTDIRECTORY=C:\Agent\_work
AGENT_SERVEROMDIRECTORY=C:\Agent\externals\vstsom
AGENT_TEMPDIRECTORY=C:\Agent\_work\_temp
AGENT_TOOLSDIRECTORY=C:\Agent\_work\_tool
AGENT_VERSION=2.122.1
AGENT_WORKFOLDER=C:\Agent\_work
BUILD_ARTIFACTSTAGINGDIRECTORY=C:\Agent\_work\2\a
BUILD_BINARIESDIRECTORY=C:\Agent\_work\2\b
BUILD_BUILDID=2036
BUILD_BUILDNUMBER=Database Build_20190708.2
BUILD_BUILDURI=vstfs:///Build/Build/2036
BUILD_CONTAINERID=2281
BUILD_DEFINITIONNAME=Database Build
BUILD_DEFINITIONVERSION=17
BUILD_QUEUEDBY=Smith, John
BUILD_QUEUEDBYID=8c588342-b87a-40cb-9b8c-a0ed10b57a3f
BUILD_REASON=Manual
BUILD_REPOSITORY_CLEAN=false
BUILD_REPOSITORY_GIT_SUBMODULECHECKOUT=False
BUILD_REPOSITORY_ID=$/
BUILD_REPOSITORY_LOCALPATH=C:\Agent\_work\2\s
BUILD_REPOSITORY_NAME=Collection
BUILD_REPOSITORY_PROVIDER=TfsVersionControl
BUILD_REPOSITORY_TFVC_WORKSPACE=ws_2_2
BUILD_REPOSITORY_URI=http://TFSSERVER:8080/tfs/Project/
BUILD_REQUESTEDFOR=Smith, John
BUILD_REQUESTEDFOREMAIL=John.Smith#Mailinator.com
BUILD_REQUESTEDFORID=7a588222-b66a-40ee-9b2a-a0ba10b12a3f
BUILD_SOURCEBRANCH=$/Collection/Project/Code
BUILD_SOURCEBRANCHNAME=Code
BUILD_SOURCESDIRECTORY=C:\Agent\_work\2\s
BUILD_SOURCEVERSION=9811
BUILD_SOURCEVERSIONAUTHOR=Smith, John
BUILD_SOURCEVERSIONMESSAGE=Added missing permission
BUILD_STAGINGDIRECTORY=C:\Agent\_work\2\a
You can list all Environment Variables with the following command:
get-childitem ENV:\
I am assuming you could create a simple build job that executes this and then look at the console output to determine what the name is of the Environment Variable you need.
I have a list of email ids in a Jenkins environment variable(emailsdl) and trying to use this for recipients: in Jenkins Pipeline Mailer as below:
mail (to: 'Mailer', recipients: '${env.emailsdl}',
subject: "Job '${env.JOB_NAME}' (${env.BUILD_NUMBER}) is waiting for input",
body: "Please go to ${env.BUILD_URL}.")
With the above code I am not receiving email and receiving an error:
Email not sent. No recipients of any kind specified ('to', 'cc', 'bcc').
But when I replace ${env.emailsdl} with real email(xyxyx#foo.com) then it does trigger an email. I even tried env['emailsdl'] and it didn't work.
Is there a way I can pass environment variable for recipients in this case?
In groovy if you use single quoted string it will not be interpolated, which means that in the string '${env.emailsdl}' the variable env.emailsdl will not be replaced. You need to use double quoted string: "${env.emailsdl}"
#Gergely: Your suggestion helped me resolving my issue. The problem is that I have a local environment variable which was assigned with a value from other global environment variable: globalVar = xyxyx#foo.com and emailsdl=${globalVar} is in job's local properties. Now I am calling this emailsdl in pipeline script. This has been resolved by:
env.((env.emailsdl).replaceAll("\$", ""))
I am trying to run custom script on windows AWS AMI. The steps I am using is as given here:
http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/mon-scripts-powershell.html
My Instance is already associated with IAM role and credential file path is set.
I am trying to run following command in power-shell:
.\mon-put-metrics-mem.ps1 -mem_util -mem_used -mem_avail -page_avail -page_used -page_util -memory_units Megabytes
The error I am getting is:
Cannot bind argument to parameter 'Path' because it is an empty string.
Your script is not able to see AWS_CREDENTIAL_FILE env var.
So try loading ur credential file
setx AWS_CREDENTIAL_FILE C:\aws\myCredentialFile.txt'
Then open a new powershell window because if you attempt to run it in the same window, it will not see the AWS_CREDENTIAL_FILE env var. Now try running
.\mon-put-metrics-mem.ps1 -mem_util -mem_used -mem_avail -page_avail -page_used -page_util -memory_units Megabytes -verbose
I have a requirement to use powershell to configure IIS7.5 on WebApplications that have not yet had code deployed (possibly at all, possibly old/broken web.configs exist) to the file system. I would like to be able to do this all at the APPHOST level. (Note at the bottom about use of Powershell > AppCmd).
I can SET all the values properly, however, being somewhat diligent, I like to also validate the values were set properly by retrieving them after setting.
Here's the scenario:
I can set this value using AppCmd so the setting is applied at the APPHOST level using the /Commit:APPHOST flag. However, I havent found a way to READ the values exclusively at the APPHOST level.
Setting the Code is successful:
C:\Windows\System32\inetsrv\appcmd.exe set config "webSiteName/webAppName" -section:system.webServer/security/authentication/anonymousAuthentication /enabled:"True" /commit:apphost
However, I cant find a way to read the values using AppCmd (or Powershell):
Running the following AppCmd returns an error due to the broken pre-existing web.config in the folder (the specific error is unimportant, as it is reading the WebApp's web.config instead of the ApplicationHost.config/APPHOST):
C:\Windows\System32\inetsrv\appcmd.exe list config "MACHINE/WEBROOT/APPHOST/webSiteName/webAppName" -section:system.webServer/security/authentication/anonymousAuthentication
ERROR ( message:Configuration error
Filename: \\?\c:\inetpub\wwwroot\webSiteName\webAppName\web.config
Line Number: 254
Description: The configuration section 'system.runtime.caching' cannot be read because it is missing a section declaration
. )
Note: I would prefer to do this all in Powershell instead of using AppCmd, so if anyone has the syntax for modifying the APPHOST settings for anonymousAuthentication section of a WebApplication, that lives under a Website, from inside Powershell (Get-WebConfiguration seems to only use the WebApp web.config), that would be totally awesome and much appreciated!
Here's how to do this in PowerShell:
[Reflection.Assembly]::Load(
"Microsoft.Web.Administration, Version=7.0.0.0,
Culture=Neutral, PublicKeyToken=31bf3856ad364e35") > $null
$serverManager = New-Object Microsoft.Web.Administration.ServerManager
$config = $serverManager.GetApplicationHostConfiguration()
$anonymousAuthenticationSection = $config.GetSection("system.webServer/security/authentication/anonymousAuthentication", "simpleasp.net")
Write-Host "Current value: " $anonymousAuthenticationSection["enabled"]
# Now set new value
$anonymousAuthenticationSection["enabled"] = $true
$serverManager.CommitChanges()