Unable to determine the workspace using TF.exe in Jenkins - jenkins

I've tried to run TFS command line in the Jenkins. However, I got this message error: unable to determine the workspace. You may be able to correct this by running "tf workspaces /collection:TeamProjectCollectionUrl".
I checked the workspace and it is correct. Ex.: tf workspaces
I checked the map and it is correct. Ex: tf workfold.
I ran the get command, informing the login and password and it didn't work in the Jenkins.
I ran this command in the powershell (outside jenkins) and the cmd worked well, however, If I ran get command (call via bat and powershell) in the jenkins, It didn't work.
Why did tfs commands work well outside the Jenkins and the Jenkins didn't?
Could anyone help me?
Thank you!

You could try to specify more parameters in your command line:
tf workspaces [/owner:ownername][/computer:computername][/collection:TeamProjectCollectionUrl][workspacename][/login:username,[password]]
I've tested with parameters /collection and /login in Jenkins, got a successful result:

Related

Runnnig remote command form jenkins using PsExec.exe gives handle is invalid error

I am trying to run a remote command from Jenkins.
I am able to run the command from the agent directly successfully.
But when I am trying the same command from the Jenkins it gives me below error.
I found the same issue here.
I tried all the solution provided there but its still not working.
Any help would be appreciated.

Jenkins perforce triggered build on windows?

I feel totally in the dark, and hope you guys can help.
So I have a jenkins server setup connect to p4v and everything running smoothly.
I can trigger the builds on jenkins manually without any problems.
Now however I'd like to setup so Jenkins (using the perforce plugin) acually polls from perforce everytime I submit something new in a specific folder.
This seems fairly straightforward running on linux, just adding a script file in perforce and a perforce trigger to run that file using curl to send a message to jenkins to start the build.
However i'm running windows, and I dont find any information about how to solve this particular problem on windows. Anyone, to help?
The main problem seems to be that all tutorials I find on this uses a .sh script which isnt run in windows, I wonder if there is some other way to do this in windows?
I managed to solve this by using the following Jenkins plugin:
https://wiki.jenkins.io/display/JENKINS/Build+Token+Trigger+Plugin
and curl:
https://curl.haxx.se/
If someone else has the same issue here is the step by step process I went through to set it up on Windows.
In your Jenkins project, enable: Trigger builds remotely (e.g., from scripts)
Enter an Authentication Token, can be anything, ex: buildCode
On the command line as p4 admin enter: p4 triggers
In the trigger, file go to the bottom
Enter the actual p4 trigger: SomeTriggerName change-commit //DepotLocationToTriggerOn/... %//DepotLocationOfScriptToBeTriggered/trigger.bat%
Observe: When the batch file to be run in the trigger is in a depot path it must be surrounded by %
Submit the trigger.bat to p4 in the choosen location. The batch file need to contain the following code C:\curl-7.60.0-win64-mingw\bin\curl.exe -u userID:APIToken JenkinsIP/job/TestJob/build?token=buildCode
Curl must be in that specific folder on the p4v server machine.
The userID and APIToken is found by going to the user drop down and enter Configure, then clicking API Token.
Hope this might help someone else with a similar problem :).

Jenkins - Copy build log from master to a shared drive

Can someone direct me here? I have a simple job configured in Jenkins on a WINDOWS environment (master and all slaves running on windows) and the job is supposed to run on a particular slave. When you build the job, the build log ( log.log) gets stored in ” %JENKINS_HOME%\jobs\\builds\%BUILD_NUMBER%\” on the master.
I do have a Jenkins workspace (which is required when you add a slave node) set on the slave for this job–where nothing gets stored when the job runs.
With this scenario, I would like to copy the build log (log.log file that’s available on the master) to a share drive. Please advise me the way to get this done. I have tried few plugins “Copy to slave”, “Copy Artifact Plugin” and ArtifactDeployer Plugin…I could not get them working to meet what I need.
Use a second build action with the execute batch option. Put the copy command there to copy the log to another location.
The following command kind-of works:
curl ${BUILD_URL}consoleFull -o ${TargetDir}/Log.txt
where
TargetDir="${WORKSPACE}/Directory/target"
BUILD_URL and WORKSPACE are set by Jenkins. Unfortunately Jenkins doesn't copy the whole log. I've tried consoleText and gotten the same result: partial logs files. :-(

How can I report the current tfs user from tf.exe?

How can I report from my build scripts who the current tfs user is?
I'm setting up automated builds with TFS 2013 and VSO and I'm having workspace errors.
I'm unable to checkout files through the build script.
I'd like to know what the user is running the tf.exe command (I've already had issues with the user running the build being automatically set to a Network Service user, who has not permissions)
In any of the pre-/post-script print the USERNAME variable. In Powershell
Write-Output "Running as '$env:USERNAME"
In a batch file
echo Running as %USERNAME%

Building code from Jenkins using TFS

I am trying to use Jenkins to build my code which resides in a https://*.visualstudio.com/DefaultCollection.
I have tried to manually check the code out using a script in jenkins e.g.
tf workspace /delete JENKINS /noprompt /collection:https://*******.visualstudio.com/DefaultCollection /login:mylogin#myaccount.com,mypassword
tf workspace /new JENKINS /noprompt /collection:https://*******.visualstudio.com/DefaultCollection /permission:Private /login:mylogin#myaccount.com,mypassword
tf workfold /workspace:JENKINS /s:https://*******.visualstudio.com/DefaultCollection /map "$/MyProject" "%WORKSPACE%"
tf get /force /recursive
This runs fine from the command line but fails in Jenkins with
TF30063: You are not authorized to access
Jenkins is running as Local System Account. I have tried the plugin for jenkins which no joy either. This also failed on authentication.
Even if you have no intention of using it, I'd install and configure the TFS build controller software. This will create the authentication link between the cloud instance and the system profile. Jenkins, running in that user profile context, should then be able to issue TF commands and create workspaces.
That said, I'd also create a build service account and not use SYSTEM.

Resources