TFS, is there a variable for the artifact zip file name? - artifacts

Is there a way to get the artifact file name easily? Looks like TFS already knows this as shown in the log below:
No path specified for search pattern: *.zip defaulting to: F:\TFS2017_Release_Agent\_work\r1\a
2017-12-08T16:38:36.8519067Z Searching for: *.zip under directory: F:\TFS2017_Release_Agent\_work\r1\a
2017-12-08T16:38:36.8519067Z Found: 1 files to extract:
2017-12-08T16:38:36.8519067Z F:\TFS2017_Release_Agent\_work\r1\a\ZFJ0_ServiceSearchPlusBuildDefn\BETALink.Service.SearchPlus\ZFJ0_BETALink10.4 DevOps_BETALink.Service.SearchPlus_1.0.0_886.zip
2017-12-08T16:38:36.8519067Z Creating destination folder: F:\TFS2017_Release_Agent\_work\r1\a\48
2017-12-08T16:38:36.8519067Z Extracting file: F:\TFS2017_Release_Agent\_work\r1\a\ZFJ0_ServiceSearchPlusBuildDefn\BETALink.Service.SearchPlus\ZFJ0_BETALink10.4 DevOps_BETALink.Service.SearchPlus_1.0.0_886.zip
2017-12-08T16:38:36.8519067Z [command]F:\TFS2017_Release_Agent\_work\_tasks\ExtractFiles_5e1e3830-fbfb-11e5-aab1-090c92bc4988\1.112.1\7zip\7z.exe x -oF:\TFS2017_Release_Agent\_work\r1\a\48 F:\TFS2017_Release_Agent\_work\r1\a\ZFJ0_ServiceSearchPlusBuildDefn\BETALink.Service.SearchPlus\ZFJ0_BETALink10.4 DevOps_BETALink.Service.SearchPlus_1.0.0_886.zip
2017-12-08T16:38:36.8987827Z

For others, I have to write a couple of lines to get the zip file name. ZFJ0_ServiceSearchPlusBuildDefn.DefinitionName is my {Artifact alias}:
$zipdir = "$(System.DefaultWorkingDirectory)\$(Release.Artifacts.ZFJ0_ServiceSearchPlusBuildDefn.DefinitionName)\$(Release.DefinitionName)"
Write-Host "zipfile directory: "$zipdir
$zipfile = Get-ChildItem -Filter *.zip "$zipdir"
Write-Host "zipfile : "$zipfile

An artifact isn't "a file". In your specific case, it is. But in general, an artifact can contain any number of files.
There is no way to retrieve the files present in an artifact, since an artifact can also be a pointer to a UNC share.

Related

Colab how to get file id for existing file

I am starting with colab for ml and I have problem importing files from my google drive into the notebook. Say I got a file pretrained_vgg19.mat in my drive like drive/jupyter/pretrained_vgg19.mat. The code snippet for importing files from drive says that I need to use the file_ID that looks like laggVyWshwcyP6kEI-y_W3P8D26sz. How do I get this file_ID?
See PyDrive documentation for the ListFile command:
from pydrive.drive import GoogleDrive
drive = GoogleDrive(gauth) # Create GoogleDrive instance with authenticated GoogleAuth instance
# Auto-iterate through all files in the root folder.
file_list = drive.ListFile({'q': "'root' in parents and trashed=false"}).GetList()
for file1 in file_list:
print('title: %s, id: %s' % (file1['title'], file1['id']))
Now all you need to do is tweak the search parameters, since you know the title of the file already. See docs.
file_list = drive.ListFile({'q': "name='pretrained_vgg19.mat' and trashed=false"}).GetList()
for file in file_list:
print('%s' % (file['id']))
Note that it is possible to have files with the same folder name and file name, because you can create multiple folders with identical paths in Google Drive. If there is even a chance of this, you will get multiple files returned in your list operation and will need to use some other criteria in order to select the correct one.
user244343's answer didn't work for me since the gauth object doesn't exist. I did this instead (test.zip needs to point to the right folder and file in your Drive!):
!apt-get install -qq xattr
filename = "/content/drive/My\ Drive/test.zip"
# Retrieving the file ID for a file in `"/content/drive/My Drive/"`:
id = !xattr -p 'user.drive.id' {filename}
print(id)

Globbing pattern to exclude files in directory, but include subdirectories

I have the following file hierarchy:
scripts
someConfigFile.js
anotherConfigFile.js
someModuleDirectory
someModule.js
anotherModuleDirectory
anotherModule.js
subDirectory
thirdModule.js
I want to match all the files in the module directories, but excude the config files contained in the scripts directory itself, using Glob:
var glob = require('glob');
console.log(glob.sync(unknownGlobPattern));
Required output (unordered):
[
'someModuleDirectory/someModule.js',
'anotherModuleDirectory/anotherModule.js',
'anotherModuleDirectory/subDirectory/thirdModule.js'
]
The following glob should work:
['./scripts/**/*', '!./scripts/*']
First part will include all files in all subdirectories. Second part will exclude files in starting directory.

Gassetic looking for file with _0 added to file name

In my gassetic.yml file I have the following
files:
app.css: # This is the output filename
- src/someBundle/app.scss
However when gassetic runs, I get an error saying src/someBundle/app_0.scss is missing.
If I create this file and edit it, its this app_0.scss that is compiled.
Why does gassetic / gulp look for this file when its not specified in my yml file?
Thanks
It adds index of the file in the folder to avoid overwritting.
I think this is a bug but you can fix it by adding autoRenaming: false to the dev environment. See Multiple Environments setup

SSIS Script Task append a line to file

I would Like to add footer to all the files in a directory
below command works when i gave one file name .
but when i try *.csv to append footer to all the files in a directory it fails .
System.IO.File.AppendAllText(#"C:\Users\ibm\*.csv", "My Custom Footer");
Thanks.
What would you expect? AppendAllText clearly states
path
Type: System.String
The file to append the specified string to.
If you need to perform the same task against multiple files you will need to enumerate through all the files in a given folder
Code approximately
foreach(string fileName in System.IO.Directory.GetFiles(#"C:\Users\ibm", "*.csv")
{
System.IO.File.AppendAllText(fileName, "My Custom Footer");
}

Issue in creating Zip file using glob.glob

I am creating a Zip file from a folder (and subfolders). it works fine and creates a new .zip file also but I am having an issue while using glob.glob. It is reading all files from the desired folder (source folder) and writing to the new zip file but the problem is that it is, however, adding subdirectories, but not adding files form the subdirectories.
I am giving user an option to select the filename and path as well as filetype also (Zip or Tar). I don;t get any problem while creating .tar.gz file, but when use creates .zip file, this problem comes across.
Here is my code:
for name in (Source_Dir):
for name in glob.glob("/path/to/source/dir/*" ):
myZip.write(name, os.path.basename(name), zipfile.ZIP_DEFLATED)
myZip.close()
Also, if I use code below:
for dirpath, dirnames, filenames in os.walk(Source_Dir):
myZip.write(os.path.join(dirpath, filename) os.path.basename(filename))
myZip.close()
Now the 2nd code taks all files even if it inside the folder/ subfolders, creates a new .zip file and write to it without any directory strucure. It even does not take dir structure for main folder and simply write all files from main dir or subdir to that .zip file.
Can anyone please help me or suggest me. I would prefer glob.glob rather than the 2nd option to use.
Thanks in advance.
Regards,
Akash
Glob by design does not expand into subdirectories. It follows UNIX style path rules and expansions see the documentation for fnmatch for more information. If you want to get at the subdirectories you need to add it to the path. This example will get everything at one level down.
for name in (Source_Dir):
for name in glob.glob("/path/to/source/dir/*/*" ):
myZip.write(name, os.path.basename(name), zipfile.ZIP_DEFLATED)
myZip.close()
Doug Hellman has an excellent discussion here. If you are not using the pattern features of glob (like *.txt for all text files or *[0-9].txt for all text files that have a number before the extension) then I think your os.walk solution is better