Release Pipeline unpack the zip and replace azure and connect the linux server throught ssh to copy files - azure-devops

I need to unzip the build zip file and replace the variables define in release pipeline by using replace token task in properties file after that i need to deployed in linux server by using ssh copy files task.
Below are the steps I am doing
I created extract file task there i mention Destination folder : $(Build.SourcesDirectory)
After that i created replace token task Root directory given $(Build.SourcesDirectory) from this directory find the properties file and replace the variables
Then I created copy files to over SSH here i gave Source folder $(Build.SourcesDirectory) to Target folder /home/*/-CICD ( deployment folder path in linux server).
Is this a correct apporach? do we have anyother option for this requirment.
please guide me .

Related

Query : Folders within Self hosted agent in Azure Devops

I have a build pipeline created using a self hosted agent with source as GIT repo.
Within the build pipeline, I am using Copy files task with the source folder being 1 folder path within the GIT repo and target folder being : $(build.artifactstagingdirectory)/DF/
When I execute the pipeline and I login into the Self hosted agent , I observe the below set of folders:
where folder 2 and 3 are unique for each different pipeline (that is my guess )
And within the folder:
So van someone signify what does each folder which is autogenerated signify?
The number '1' '2'...'6' of work folder c:\work\1, c:\work\2... in your build agent which stands for a particular pipeline.
Agent.BuildDirectory
The local path on the agent where all folders for a given build
pipeline are created. This variable has the same value as
Pipeline.Workspace. For example: /home/vsts/work/1
a folder:
The local path on the agent where any artifacts are copied to before
being pushed to their destination. For example: c:\agent_work\1\a
b folder:
The local path on the agent you can use as an output folder for
compiled binaries.
By default, new build pipelines are not set up to clean this
directory. You can define your build to clean it up on the Repository
tab.
For example: c:\agent_work\1\b
s folder:
The local path on the agent where your source code files are
downloaded. For example: c:\agent_work\1\s
TestResult folder:
The local path on the agent where the test results are created. For
example: c:\agent_work\1\TestResults

azure devops: copy file to artifact folder to access in release pipeline

I am creating a build for ios using azure and I want to copy a certificate file to artifact folder created to use in the release pipeline.
I am using a copy task and after the task is done its job, I am not able to find a copied file at the desired artifact folder. there are answers for copy task but not working for my scenario.
or is there any way to access files from the source folder of build pipeline to from release pipeline?
You were using download secure files task to download the cert files. As below described: see here for more information.
Once downloaded, use the name value that is set on the task (or "Reference name" in the classic editor) to reference the path to the secure file on the agent machine. For example, if the task is given the name mySecureFile, its path can be referenced in the pipeline as $(mySecureFile.secureFilePath). Alternatively, downloaded secure files can be found in the directory given by $(Agent.TempDirectory)
The secure files are downloaded to directory $(Agent.TempDirectory) and its path can be referenced by $(mySecureFile.secureFilePath) if you set the reference name to mySecureFile
So that the copy files task of yours need to be configured as below: Set the Source Folder to $(Agent.TempDirectory) and Contents to the name of the secure files. See below example:
You can also set the Contents to $(certFile.secureFilePath) $(provisionFile.secureFilePath) if you set the Reference name of above download secure file tasks to certFile and provisionFile
More conveniently you can use download secure files task directly in release pipeline to download the cert files.
Then the secure files will be available in release pipeline, and can be referenced just like in the build pipeline.

Execute SQL scripts on VM Machine using release azure devops pipeline

I am using IIS Deployment template in Release pipeline to deploy MVC application to VM and it is working fine. But after deploying application, we want to run any ad-hoc sql changes using script files in SQL server using custom task Run SQLCMD Scripts from VSTS market place.
Relese pipeline, scripts are in zip file, Can anyone suggest what we should key-in in "Path to folder containing SQLCMD script files"?
You can try referencing the variable
$(Build.ArtifactStagingDirectory)
In Release Pipeline, the artifacts will be downloaded to the path : $(System.ArtifactsDirectory).
According to your screenshot, I noticed that you are using the "Extract files" task. This task will find the zip files in the $(System.ArtifactsDirectory) and extract it.
The unzipped folder name is set in the "Extract files" task (Destination folder).
So you could try to use the following path:
$(System.ArtifactsDirectory)/Destination folder name
You can also expand this path according to the actual location of the file.
Hope this helps.

Azure DevOps - During the build pipeline run, what is the path where the Agent downloads the files locally?

We are using a Microsoft Hosted Agent to run a build pipeline for an automated test scenario for our application. What we would like to achieve is, having our automation procedure, to download a file (from a headless chrome browser), then navigate to the path where it is downloaded and open it.
How could I find the path where the files are being downloaded inside the Agent?
Quick compilation of list of pre-defined variables related to paths for the build on linux and windows self hosted agents from official doc link.
The one you are looking is Agent.BuildDirectory or Pipeline.Workspace.
List of predefined variables:
Variable type
Variable
Description
Example
Agent
Agent.BuildDirectory
The local path on the agent where all folders for a given build pipeline are created
D:\..\agent\_work\1
Agent
Agent.HomeDirectory
The directory the agent is installed into
C:\agent
Agent
Agent.TempDirectory
A temporary folder that is cleaned after each pipeline job
D:\..\agent\_work\_temp
Agent
Agent.ToolsDirectory
The directory used by tasks such as Node Tool Installer and Use Python Version to switch between multiple versions of a tool
D:\..\agent\_work\_tool
Agent
Agent.WorkFolder
The working directory for agent
c:\agent_work
Build
Build.SourcesDirectory
The local path on the agent where your source code files are downloaded.
c:\agent_work\1\s
Build
Build.ArtifactStagingDirectory
The local path on the agent where any artifacts are copied to before being pushed to their destination. A typical way to use this folder is to publish your build artifacts with the Copy files and Publish build artifacts tasks
c:\agent_work\1\a
Build
Build.StagingDirectory
The local path on the agent where any artifacts are copied to before being pushed to their destination.
c:\agent_work\1\a
Build
Build.BinariesDirectory
The local path on the agent you can use as an output folder for compiled binaries
c:\agent_work\1\b
Build
Build.Repository.LocalPath
The local path on the agent where your source code files are downloaded.
c:\agent_work\1\s
Build
Common.TestResultsDirectory
The local path on the agent where the test results are created.
c:\agent_work\1\TestResults
Pipeline
Pipeline.Workspace
The Workspace directory for a particular pipeline
/home/vsts/work/1
System
System.DefaultWorkingDirectory
The local path on the agent where your source code files are downloaded.
c:\agent_work\1\s
When you install the agent, you specify the work directory. In pipeline tasks, you can find out exactly where within that directory files are staged with variables like $(Agent.BuildDirectory). This might not be the exact location you need, but I think it is in the right direction.
For a complete list of predefined variables, see here: https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml
You can check this document:
So for Linux its default location /home/<username>/Downloads.
I do the test in Microsoft hosted agent-window2019 with test C# code(Hint from Daniel!) like:
static void Main(string[] args)
{
string FILEURI = "https://www.nuget.org/api/v2/package/Cauldron.Newton/2.0.0";
System.Diagnostics.Process prozess = new System.Diagnostics.Process();
prozess.StartInfo.FileName = #"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe";
prozess.StartInfo.Arguments = "--download " + FILEURI;
prozess.Start();
Console.WriteLine("Test starts.");
}
And then I use command like dir c:\users\VssAdministrator\cauldron.newton.2.0.0.nupkg /s /b to find the location of downloaded file: cauldron.newton.2.0.0.nupkg.
Then i confirmed the default download location of Chrome is still C:/Users/{user}/Downloads, same as using self-agent or downloading locally. (VssAdministrator is user when run windows hosted agent)
So I think Linux hosted agent should have similar behavior. You can try to find your file from /home/<username>/Downloads folder. Hope it helps.

Dynamic Bin folders hard to copy bin folder to artifact location Azure DevOps

I have a problem with my CI in Azure DevOps.
I need to have a generic PowerShell script run in each CI that copy files from the bin folder and put them to artifact(a) folder with each project folder name.
But bin path are dynamic e.g.
$projectBinDirectory\bin\release\net471\win-x64
$projectBinDirectory\bin\release\net471
$projectBinDirectory\bin\Release\netcoreapp2.1\win-x64
$projectBinDirectory\bin\Release\netcoreapp2.2\win-x64
$projectBinDirectory\bin\Release\netcoreapp2.1
in the future, if someone creates netcore 2.2 or something else how to configure publish path dynamically as I want to copy main project files
e.g.
copy from
bin\release\netcoreapp2.1\win-x64 all project *.dlls,*configs etc files
to
artifact\Projectname\ all project files
the issue
cannot figure out after bin\release\ path to reach to project files
I need to figure out what is the path dynamically after bin\release...\projectFiles
this argument fixed my issue
-c Release -o ./bin/$(BuildConfiguration)/publishNew: