Deploy a test site azure devops pipeline (LAMP) - azure-devops

So I've been looking at getting the pipeline build for automation E2E Acceptance testing going.
I've been able to get the pipeline running on an agent, now the default path that the code is checked out to is
/home/myusername/myagent/_work/1/s
which is $(Pipeline.Workspace), and cannot be changed to custom path like /var/www/html/ and accepts only relative path as described here.
If I try to point the apache webroot to the above dir, I get the forbidden error. I tried
running apache as the directory owner as described here
giving full 777 permission to the directory
Now, how do I get apache to interact with those files or checkout the files inside the apache webroot /var/www/htmlin the first place so no additional work is required?
OS: Ubuntu 18

Related

Post Build event that works on both Azure DevOps and Local PC

I have a VS2017 solution that Builds both locally and also on Azure DevOps.
I now need to run a Post Build script to run an EXE. I have this working on my local machine, but I guess there will be an issue with the Path to the EXE which has been added to the DevOps Library.
Note. The EXE is all installed on DevOps and runs fine from a Command Line Task - I just need it to run as a post build on one of the projects so that this project is ready to be packaged in the Installer SetUp project. (During a full Solution build).
This represents the Local Post Build script - How do I handle this on Azure, where the path will be different?
"C:\Program Files (x86)\{dir}\{app}.exe" -file "$(ProjectDir){file.txt}"
Any help appreciated. Thanks!
This represents the Local Post Build script - How do I handle this on
Azure, where the path will be different?
$(ProjectDir) is msbuild property, so it works on both Azure DevOps and Local PC. You only need to pay attention to the {dir} of the xx.exe.
My suggestion is to put the exe in solution folder (where the xx.sln file exists), then you can use script like "$(SolutionDir)\{app}.exe" -file "$(ProjectDir){file.txt}". The $(SolutionDir) and $(ProjectDir) can be recognized by msbuild. (It works for both local pc and online devops.)
Or you can put the xx.exe under root directory of your git repo, then use $(System.DefaultWorkingDirectory) as the path of your xx.exe, but it only works for online devops, it can't work on local PC. (Not recommended)

How to deploy Strapi to Azure via pipelines

I am quite new with Strapi, it is my first time to deploy it.
I have Strapi with MongoDB (Atlas) which work on localhost.
Now I want to deploy to Azure with keeping MongoDb on Atlas.
So my jobs for now are
Authentification
npm install
PowerShell -> install strapi cli and build my strapi project
I get en error on the last step.
My questions are
"Is it possible to use pipeline on Azure to deploy Strapi?"
and
"Can somebody explain my how to do this right?".
I would appreciate any help!!!
Above error is caused by strapi installation location not being added to the PATH environment variable of the agent machine.
You will have to add strapi installation location to PATH environment variable.
Run echo "##vso[task.setvariable variable=PATH]${env:PATH};installationFolder" in the script tasks to set PATH environment variable on hosted agent machine. Check here for more information about setting variables in scripts
On hosted agents the default installation location for yarn is C:\npm\prefix\bin rather than %LOCALAPPDATA%\Yarn\bin. See this similar thread.
So the powershell script looks like this echo "##vso[task.setvariable variable=PATH]${env:PATH};C:\npm\prefix\bin". See below screenshot.
Noted:
The change of PATH environment variable on hosted agent will only take effect in the following tasks. You need to run strapi build in a separate powershell task. See below:
Run strapi build in the following powershell task

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.

mkdocs site doesn't exist after build on codeship

I'm trying to use codeship to automate building docs from a repository.
After the Executing the command mkdocs build --clean I get a path to where my site folder is supposed to be.
INFO - Cleaning site directory
INFO - Building documentation to directory: /home/rof/src/bitbucket.org/josephkobti/test/site
The thing is that I can't find that folder using the ssh console for debugging.
The reason for the folder not existing was a misunderstanding of Codeship's SSH Debug Build feature, documented here https://documentation.codeship.com/basic/builds-and-configuration/ssh-access/
The VMs started for the debug feature are not the actual VMs that run the automated builds. They are new VMs running the same initialization steps as the automated builds (i.e. cloning the repository, configuring project specific environment variables, ...) but none of the actual setup or test commands.
Because of this the mkdocs build --clean command wasn't run either when Joseph connected via to the debug VM, and as such the generated site wasn't available.

How to access the generated File by jenkins server through URL?

I am using jenkins.
In Each build I execute from Jenkins I am storing a build number in a Test file called Build.txt
Which is in opt/jenkins/ path.
I want to access this file through an URL from a browser.
Is it possible and How can I achieve it?
you can artifact the build files using
Post build -> Archieve artifacts
you can see those archieved files in URL using below plugin
https://wiki.jenkins-ci.org/display/JENKINS/Archived+Artifact+Url+Viewer+PlugIn
The solution is to use Jenkins userContent directory. Jenkins has a mechanism known as "User Content", where administrators can place files inside $JENKINS_HOME/userContent, and these files are served from http://yourhost/jenkins/userContent.
Make sure your jenkins have Copy To Slave Plugin installed.
In your job config page, Add Post-build Action-->Copy files back to the job's workspace on the master node.
In the Files to copy field, fill in the files that you want to copy from the slave node back to the jenkins master's corresponding workspace of current job.
Goto your $JENKINS_HOME/userContent folder, create a link to $JENKINS_HOME/jobs/yourjob/workspace/screenshot by issuing command for example:
ln -s screenshot /home/ci/jenkins/jobs/tc_ui_test/workspace/screenshot/
After that, you can access your contents from url: http://yourhost/jenkins/userContent/screenshot