Teamcity, passing the user who triggered the build to powershell script - teamcity

I would like to pass my powershell build step script the user who is currently logged in teamcity and triggered the build to run. I have tried to approach it in a different way where a user checks in a file which would contain the users user name but my PM insists that I use teamcity to pass the user. I have tried
%teamcity.auth.userid% or %System.teamcity.auth.userid% or %env.username% or
%teamcity.agent.jvm.user.name%
and none of them are giving me the proper user name. Could someone help please ?

Try teamcity.build.triggeredBy.username

Related

Maven build configuration Team city - Pass variable to feature file

I have a cucumber feature file scenario for performing smoke test and a track server which should be passed dynamically , below https://tk2.dev.summitenergy.com should be passed as a parameter variable( not hardcoded)
Scenario: RA Login functionality
Given Open Firefox and start "https://tk2.dev.summitenergy.com"
When I enter "atesting" and "Testing#2"
Then user should be login successfully
for that i have given "MAVEN_OPTS="-Dprop=%teamcity.project.id%" mvn surefire:test" in the Additional command line parameters feild while build configuration , I am not sure if it is the correct way to do
Can you please suggest me the correct way
Thanks
Ramesh
As cucumber in maven is executed as JUnit test, please try to set following value in Additional Maven command line parameters
-DargLine="-Dprop=%teamcity.project.id%"
Note, that you do not need to put MAVEN_OPTS into field's value
Also, Goals are separate field, too. That is where test goal should be specified

How to hide TeamCity configuration for selected users?

I have one TeamCity project Dac.Test that contains 3 configurations: DEV, QA, PROD.
Also I have some users associated with their Roles. Is this possible to hide / show certains configurations for selected users or groups?
For example: Users associated with group: Testers can see QA configuration, but not PROD and DEV.
There is no way of managing user permissions per-build, this is available on a project level only. You could create a sub-project in the Dac.Test project to cater for this
If you're looking for a way of stopping people from mistakenly running this build, the following approach will work.
This method uses a prompt box that will pop up after you click the run button, it also needs input from the user confirming that they mean to run the build.
No one can run this build by accident
Go to your build configuration in the TeamCity UI
From here, go to Edit Configuration Settings --> Parameters --> Add new parameter
Enter something like 'Confirmation' as the parameter name
Then beside 'Spec:', click the 'Edit...' button
Set up the parameter as shown in the following screenshot:
You will now be prompted and asked for confirmation when you click the run button. The user will have to enter 'YES' in the prompt box that appears, any other value will stop the user from building:
This is best accomplished by using TeamCity's built-in role management. Roles allow you to set fine-grained permissions for users and groups. One potential issue, however, is that roles are scoped to projects (not build configurations). You'll need to create a separate Dac.Test QA project+configuration and provide your Testers the necessary privileges there. You'll also need to make sure that they are stripped of all privileges for the Dac.Test project.

tf.exe get for different user

I use the following command to get the latest version of a branch for a specific user (not the one running the process):
tf get $/MyProject/Development /version:WmyPC;otherUser /login:otherUser,otherPassword
Bt I keep getting:
The operation cannot be completed because the user (otherUser) does
not have one or more required permissions (Use) for workspace...
Any ideas?
By default, when you create a workspace it is a 'Private Workspace' - this means that the person who created it is the only person who can "use" it (which is why you get that specific error message).
What you will want to do is change the workspace to a 'Public Workspace' - this updates the permissions and allows multiple people to use the same workspace, but using their own credentials.
For more information, see my blog post TFS2010: Public Workspaces.
You are trying to get the files on your local machine with the credentials of someone else. It is not executing the TF under other credentials.
In other words, you still use the workspace mapping of yourself.
You need to use the RUNAS command to fullfil your task: http://social.msdn.microsoft.com/Forums/en-US/tfsversioncontrol/thread/20b6f678-4657-4b14-a114-5eeb232934e2/

Error when trying to register a task with task scheduler (Win7)

To enable my application to startup with admin rights at user login, I use a task in task scheduler. And it works fine. Mostly. Now I've received bug reports saying that this fails:
rootFolder->RegisterTaskDefinition( _bstr_t(name.toWideCharPointer()), task,
TASK_CREATE_OR_UPDATE, _variant_t(L"Builtin\\Administrators"), _variant_t(),
TASK_LOGON_GROUP, _variant_t(L""), &registeredTask) -> 0x80070534
0x80070534 seems to mean "No mapping between account names and security IDs was done". I'm following (pretty much verbatim) the example at:
http://msdn.microsoft.com/en-us/library/aa381911(v=VS.85).aspx
Ideas what has gone wrong, and how to fix it ? The application has manifest set so the user needs to be admin to run it.
Question: The "Builtin\\Administrators" group, it is language dependent, isn't it ? I think that the user in question might have a non-english Windows 7. If so I imagine it would work better with specifying "S-1-5-32-544" instead ( http://support.microsoft.com/kb/243330 )
Update: So the explicit call looks like:
rootFolder->RegisterTaskDefinition(
_bstr_t(name.toWideCharPointer()),
task,
TASK_CREATE_OR_UPDATE,
_variant_t(L"S-1-5-32-544"), // Language independent "BUILTIN\Administrators"
_variant_t(),
TASK_LOGON_GROUP,
_variant_t(L""),
&registeredTask)
Make sure that the application is executed with elevated privileges, otherwise that call will fail.
The problem indeed lies in the parameter _variant_t(L"Builtin\\Administrators"), which is hard-coded to English version of Windows. By using the language agnostic security identifier "S-1-5-32-544" ( http://support.microsoft.com/kb/243330 ), the problem is resolved.
Update: So the explicit call looks like:
rootFolder->RegisterTaskDefinition(
_bstr_t(name.toWideCharPointer()),
task,
TASK_CREATE_OR_UPDATE,
_variant_t(L"S-1-5-32-544"), // Language independent "BUILTIN\Administrators"
_variant_t(),
TASK_LOGON_GROUP,
_variant_t(L""),
&registeredTask)
Make sure that the application is executed with elevated privileges, otherwise the call will fail.
After spending some time, I've seen that more modifications than just _variant_t(L"S-1-5-32-544") are needed to make this "Logon Trigger Example (C++)" example work.
All the details can be found in this answer.

Get the complete username a new username

When using NetUserAdd the user will be created on the local computer or as a domain account depending the role of the server where you used this function.
I want to retrieve the complete username (LOCALCOMPUTER\USERNAME or DOMAIN\USERNAME) to use it remotely.
Is there a function to do this?
Caveat: I haven't checked the solution.
You may call NetGetJoinInformation to know if the machine belongs to a domain and NetServerGetInfo if the code is running on a DC.
After those test you may get the machine name (GetComputerName) and domain name (NetWkstaGetInfo) and whatever you need.
Be careful if you are doing this on a cluster.
I'm sure I'm missing something, but can't you use GetUserNameEx and pass in the desired EXTENDEND_NAME_FORMAT? I believe NameSamCompatible should be the format you desire.
You'll get back either MachineName\UserName or DomainName\UserName

Resources