Can TC unzip file(s)?
Answered
Hi.
For some reason before my (unit)tests starts, I need to unzip several files. Is it possible to accomplish within built-in TC tools? You can archive (artifacts), so maybe you can unzip some files? What should I do in order to use it as build step?
Thanks in advance.
Please sign in to leave a comment.
Hi Anton,
If you obtain these files via artifact dependencies, you can unzip them in a similar way you store artifacts into an archive. See examples in the 'Artifacts Rules' section of the link.
Otherwise, you can simply add a command-line build step, where you unzip the required files.
@Mikhail Efremov : Thank you very much.
>ArchivePath is used to extract downloaded compressed artifacts.
zip,7zip,jar,tar, andtar.gzare supported.Am I right that zip or 7zip are supported, no need to additional installation/setup? Simple script which would call *zip, right?
Anton Sharov, 7zip is supported, that's correct. It's artifact rules. You don't need any scripts or installations for this to work. You just need to apply this 'syntax' in your artifacts dependency settings.
Alternatively, you can also do this with a simple command-line build step, given that your agent has 7zip installed.
Hi.
The thing is that I need to exctract some archive before test step. Here how it looks for now(separate build step):
Runner type: Simple command execution
Step name: Optional, specify to distinguish this build step from other steps.
Execute step:
Working directory:
Optional, set if differs from the checkout directory.
Run:
Custom script: *
Enter build script content:
7z.exe x test.zip
As a result I get '7z.exe' is not recognized as an internal or external command,
What I'm missing?
Hi Anton Sharov,
With a command-line build step, you need to make sure that the exact same command will successfully execute outside of TeamCity. The command-line step simply executes a given custom script as an executable batch file (*.cmd) for Windows or as a shell script for Unix (/bin/sh by default, but it can be changed with shebang). Or, if a specific executable (the 'Executable with parameters' option in the 'Run' dropdown) is specified, it calls the executable with given parameters
In your case, the executable was not found by the OS. Since you are calling '7z.exe' without a full path, you need to make sure that it can be found in the PATH environment variable for the user who runs the agent. Or you can specify the full path to the executable in the script.
Another way to solve this is to change the 'custom script' value in the 'Run' dropdown to 'Executable with parameters' and fill the path to the '7z.exe' executable. Then move all the arguments from your script to the 'Command parameters' field. The downside of this approach is that if you run this step on different agents, you will need to make sure that they have '7z.exe' at the same location).
Hi. Thank you for reply. I've already fix the issue with absolute path which I wanted to avoid. What I wanted is to use TC internal facilities to (un)zip, because you obviously can do this (artifacts). Smth like internal tools which can be called in steps. For example DSL script for build should be changed if I change TC agent installation or change Win to Linux.
Hi Anton,
I would try to use the approach with artifacts. Could you please let me know why do you avoid using it? Does the archive come from a VCS and not from artifact dependencies?
Unpacking archives during the artifacts dependencies step is coded in the agent: it does not download or use any external tools per se, hence there is no internal archive tool that can be used as a build runner or called in a build step.
There are many ways to avoid changing the DSL script and make it less dependent on the specifics of the environment. For example, you can use environment variables on agents instead of hard-coding the absolute path to the executable. Environmental variables work in both Windows and Linux. You can even configure the build to only use agents that have certain environment variables configured via agent requirements. For instance, you can use the env.VAR_NAME exists requirement (where VAR_NAME is an environmental variable configured on agents that holds the path to the executable). You can also use Powershell runner to compress or extract zip archives. Powershell will allow you to avoid specifying the path to the 7z.exe and use Expand-Archive command instead. You can use conditional build steps to run different versions of the unzip script based on certain conditions (for instance, check if the teamcity.agent.home.dir contains regular slashes or backslashes).
It all depends on the specifics of your build and the environment you use. The universal cross-platform way is to use the artifact dependencies approach.
@Mikhail Efremov
Hi. Sorry for delay.
> Does the archive come from a VCS and not from artifact dependencies?
From VCS, need to unzip folder before unit-tests stage.
The thing is that I supposed that as far as TC deal with (un)zip artifacts, it's (zip) functionality can be used transparently. Smth like you have options on build step to use .net process runner or nuget staff after nuget is installed on agent. I supposed that I can use zipping in similar manner. For now the problem is solved with command line and full path to 7z. If need I will consider use either env. variables or powershell script.