Get build agent folder path in tfs build - batch-file

How to access TFS build agent folder path in using batchfile?
I am calling runscript tool from build workflow (calling windows batchfile).
I tried to use the environment variable BUILD_REPOSITORY_LOCALPATH ($(BUILD_REPOSITORY_LOCALPATH), $env:BUILD_REPOSITORY_LOCALPATH) but they dint give any result.
Need some assistance on this.

I used another workaround for this instead of getting by workspace. From sourceDirectory folder i drill down to find my solution project file, the path containing my solution project is the local directory path i need
From batchfile i call my exe and pass %TF_BUILD_SOURCESDIRECTORY% as parameter.
string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory)
// targetdirectory would be the input parameter from batch file`
for (int i = 0; i < subdirectoryEntries.Length ; i++)
{
// My root folder always contains a specific folder with name MyFolder
// and a file Myfile.sln
if (subdirectoryEntries[i].ToString().ToLower().Contains(#"MyFolder"))
{
Console.Writeline("My source code path is " + targetDirectory);
}
//Similarly I check for Myfile.sln and then get my path.
}
This may be a very crude way, this worked for me.

The variable you are looking for is TF_BUILD_SOURCESDIRECTORY. Please refer to the XAML build documentation.

TF_BUILD_SOURCESDIRECTORY: The sources sub-directory of the build agent working directory. This directory contains your source code. For example: C:\Build\BuildBot3\CoolApp\CIBuild\src.
If you want to get C:\TFS_Build\src\V9, it's just local path: the path that you have mapped the server path to on your machine. There is not any built-in TF_BUILD environment variables could achieve your requirement.
You could use TFS API to get the related info, first get the workspace information for the build server's workspace, then do the get option, a sample code for your reference:
// Get the workspace information for the build server's workspace
var workspaceInfo = Workstation.Current.GetLocalWorkspaceInfo(sourcesDirectory);
// Get the TFS Team Project Collection information from the workspace cache
// information then load the TFS workspace itself.
var server = new TfsTeamProjectCollection(workspaceInfo.serverUri);
var workspace = workspaceInfo.GetWorkspace(server);
Once you have a workspace, you can query it for the path mappings. It
will do the necessary translation from server to local path based on
your workspace mappings. For example:
workspace.GetServerItemForLocalItem("C:\TFS_Build\src\V9");
and
workspace.GetLocalItemForServerItem("$/DEV/V9");
This mechanism will only work, however, if your build definition
actually sets up the workspace to include these files.
More details please refer this similar question: How do I resolve the root and relative paths of TFS folders on the server?
update from OP:
From sourceDirectory folder i drill down to find my solution project
file, the path containing my solution project is the local directory
path i need

Related

FileNotFoundError: [Errno 2] No such file or directory selenium\\webdriver\\remote\\getAttribute.js'

I'm working with selenium. The script is in :
C:\Users\User\Desktop\Data Analytics Arg\Proyectos\datademia\Py_install\py_ejemplo.py . Venv is activated and chromedriver.exe is in C:\Users\User\Desktop\Data Analytics Arg\Proyectos\datademia\Py_install\chromedriver.exe
The script runs perfectly. Then I created an only .exe-file via terminal :
pyinstaller --add-data "chromedriver.exe;." --windowed --onefile py_ejemplo.py
Folders are created correctly (build and dist). The .exe file (py_ejemplo.exe) was created, but when I try to run it, I get this message:
I've been looking and still can't solve it... I've tried these solutions :
filenotfound
but didn't work for me...Could someone help me? I don´t know what's wrong...
Thanks in advance
I got the same problem but I was working with Firefox and geckodriver.
In my case, I copied the selenium folder from the virtual environment to the dist folder and it worked.
There are a few things you should ensure when packing a script with pyinstaller build with selenium web driver.
It may require to add driver executable when building. I.e. chromedriver.exe
It may also require to add some package files related to selenium such as getattributes.js file when building. It was required at my project.
pyinstaller will extract those files to temp folder in AppData for windows users. So in your code, your relative paths may require to be resolved with a sample function as below (if you are running your code in vs code or you are running through pyinstaller executable the paths should be resolved by function).
For item 1 and 2, you can use --add-binary and --add-data features of pyinstaller for each of them. It is also possible to do this in *.spec file with add-files list, following your first running of pyinstaller (see this explanation) I preferred command-line option as below.
pyinstaller ./app.py --onefile --noconsole --add-binary "./driver/chromedriver.exe;./driver" --add-data "C:\Users\YOUR_USER_NAME\.conda\pkgs\selenium-3.141.0-py38h2bbff1b_1000\Lib\site-packages\selenium\webdriver\remote;selenium\webdriver\remote"
For item 3, to resolve relative paths in your source code, you can use below function in related places (for example when accessing chromedriver.exe)
def resource_path(relative_path):
try:
base_path = sys._MEIPASS
except Exception:
base_path = os.path.dirname(__file__)
return os.path.join(base_path, relative_path)
Use above function once you need to access packaged executables and files in your source code. In below example, my chromedriver is inside driver folder in my workspace. But when it is accessed through pyinstaller executable, it will be extracted to temp folder in AppData, yet function will access it through sys._MEIPASS variable set by pyinstaller.
driver = webdriver.Chrome(executable_path = resource_path('./driver/chromedriver.exe'))
Hope it works.

Meteor Server-Only Files and Temporary Downloads

In Meteor, are there any folders where I can put a .zip which will not be sent to the client?
Secondary question: how can I make temporary download links on the app, which self-destruct after a period of time?
The idea is that only the server will have access to this file. /server doesn't seem to work because any files I place in there that are not code are not included in the final bundle.
My Solution - Heroku Filesystem
This is probably not the best solution to this problem - however, to anyone else that needs to have files bundled with the app which cannot be seen by the client, here's how I did it.
Note that deleting the secure files is done because Heroku does not persist filesystem changes on restart.
Place files in a folder named "securefiles" or similar in your /public folder.
These get compiled to a folder named /static in the bundle. Note that if you're using the Heroku buildpack, the actual path to the working directory for the server is /app/.meteor/heroku_build/app/.
Next, on server start, detect if the app is bundled or not. You can do this by checking for the existence of the static folder, and there's probably other files unique to a bundle as well.
If you're bundled, copy the files out of public using ncp. I've made a meteorite package just for this purpose, use mrt add ncp to add the node copy tool to your project. I recommend copying to the root directory of the app, as this is not visible to clients.
Next, delete the folder from static.
At this point you have files which can only be accessed by the server. Here's some sample coffeescript to do this:
Meteor.startup ->
fs = __meteor_bootstrap__.require 'fs'
bundled = fs.existsSync '/app' #Checking /app because on heroku app is stored in root / app
rootDir = if bundled then "/app/.meteor/heroku_build/app/" else "" #Not sure how to get the path to the root directory on a local build, this is a bug
if fs.existsSync rootDir+"securefiles"
rmDir rootDir+"securefiles"
#Do the same with any other temporary folders you want to get rid of on startup
#now copy out the secure files
ncp rootDor+'static/securefiles', rootDir+'securefiles', ()->
rmdir rootDir+'static/securefiles' if bundled
Secure/Temporary File Downloads
Note this code has dependencies on the random package and my package ncp
It's very easy to add on to this system to support temporary file downloads, as I have done in my project. Here's how, run url = setupDownload("somefile.rar", 30) to create a temporary file download link.
setupDownload = (dlname, timeout) ->
if !timeout?
timeout = 30
file = rootDir+'securefiles/'+dlname
return '' if !fs.existsSync file
dlFolder = rootDir+'static/dls'
fs.mkdirSync dlFolder if !fs.existsSync dlFolder
dlName = Random.id()+'.rar' #Possible improvement: detect file extension
dlPath = dlFolder+'/'+dlName
ncp file, dlPath, () ->
Fiber(()->
Meteor.setTimeout(() ->
fs.unlink dlPath
, 1000*timeout)
).run()
"/dls/"+dlName
Perhaps I will make a package for this. Let me know if you could use something like that.

File cannot be found when relative path is used

In my WPF caliburn.micro application, I use ComponentOne's C1DocumentViewer to display a report.
I created in the project a new Folder “Reports” and placed the .xml there. I show the report using C1DocumentViewer. When provide the absolute path to the .xml file, it works fine. But of course I need to use a relative path. So if I make it “../../MyProject/Reports/MyReport.xml”, it works on my machine when I run it in Visual Studio. But not when I publish it using ClickOnce, it just cannot find the file. Same thing if I use “/Reports/MyReport.xml” or “Reports/MyReport.xml”.
When I try to use “Reports/MyReport.xml” when I debug in Visual Studio, it is looking for the path “Reports/MyReport.xml” in bin/Debug of the main project of the solution.
Please help. Here is my code:
protected override void OnViewLoaded(object view)
{
base.OnViewLoaded(view);
var rpt = new C1.C1Report.C1Report();
rpt.Load(#"Reports/MyReport.xml", "Recent Files Information");
rpt.DataSource.RecordSource = "MyReportProc(1)";
rpt.Render();
Report = rpt.FixedDocumentSequence;
}
Just a guess. Your problem might be related to the working directory of your process.
When the process refers to a file using a simple file name or relative
path (as opposed to a file designated by a full path from a root
directory), the reference is interpreted relative to the current
working directory of the process.
Check it with Directory.GetCurrentDirectory() when you run your program in Visual Studio and also when you run it after publishing it with ClickOnce.

How to determine branch name from batch file

I did a get latest from TFS.
My local path is:
C:\tfs\Project\Branch1\Config\Deployment\CopyInstallers.bat
TFS Path is:
$\Project\Branch1\Config\Deployment\CopyInstallers.bat
CopyInstallers.bat gets latest of installer folder from the branch at different location on the server and zips them and puts it on the shared location on server.
I have another branch named Branch2 and its TFS path is
$\Project\Branch2\Config\Deployment\CopyInstallers.bat
What I am trying is try to get the branch name using TF.exe or TFPT.exe, so that I should not har code the branch name in the CopyInstaller.bat file to get latest of installer folder.
Or is there any other way by which I can get to know the branch name / path with in the batch file?
Use the TF.EXE info command.
From the DOS Shell go to the directory in your workspace where the branch is located (C:\tfs\Project\Branch1\Config\Deployment)
Use the command : TF.EXE info .
Parse the result on the "Server Path:" line.
EDIT :
With Visual Studio 2010 replace the info command by the properties one
EDIT 2
Ok: I made you a console app, get the zip file here, there's the sources code and build exe.
Tell me if it's what you expected

How do I change the default location of the log files for GAE's bulkloader?

While working on my GAE project under my dev environment, whenever I upload data to my dev datastore, the logfiles are stored in my current directory, for instance:
C:\dev\ls
bulkloader-log-20090912.104643
bulkloader-log-20090912.104648
bulkloader-log-20090912.104731
bulkloader-log-20090912.105526
bulkloader-log-20090912.110428
bulkloader-progress-20090912.104648.sql3
bulkloader-progress-20090912.104731.sql3
bulkloader-progress-20090912.105526.sql3
bulkloader-progress-20090912.110428.sql3
project
project is my GAE app. The above is generated when I run the command appcfg.py upload_data. Is there a way to tell GAE where to store those log files, for instance in a log folder.
Use the --log_file=... option to appcfg.py, as documented here: with this command line option you can give the complete path to the log file, including folder and name. (You cannot give JUST the folder and let it figure out the name; for that, you need to write a tiny script that figures out the name then calls appcfg.py).

Resources