Azure DevOps - Pipeline to pull code down to remote server - azure-devops

I am attempting to create a pipeline in our Azure DevOps org that will automatically 'pull' code down to a single remote server whenever a push request is sent to the master branch of my particular repo. I am having a difficult time understanding the entire process and what I actually need to accomplish this relatively simple pipeline.
Currently, my remote server has a folder on the C: drive with various .ps1 files. I would like to turn this into my repo and install the self-hosted agent on this same server so that way anytime I push something to the master branch on my local server it will automatically be pulled down to my remote server and the scheduled tasks I have running will pick be running the most up to date code.
I believe what I need to do first is install a self-hosted agent on my remote server. I am not completely sure though if this agent is suppose to be a deployment agent or a build agent.. or both? Since I am not technically building a project, but rather simply overwriting .ps1 files, I imagine it should only be given permissions for a deployment agent.
Something else I can't wrap my head around is how I specify the location of my repo on the remote server. Can I define this dynamically or do I need to specify in my path the target path of that specific repo?

According to your description, you could simplify your requirement to be: copy files from a source folder to a target folder on a remote machine over SSH using Copy Files Over SSH task, and then run related Git commands like the following.
cd repo_directory
git add .
git commit -m "upadte"
git push
Thus this remote repo is updated using SSH Deployment task.
In addition, you need to deploy a self-hosted build agent because it can be used in build pipeline.
Finally, configuring a schedule trigger for this build pipeline.

Related

Versioncontrol Repository in LAN Working copy in Web

I'm a newbie to version control systems, so please pardon my naiveté.
I want the repository to be on a networked path within our local area network (LAN) so that only local PC's can access it. The files that are edited should be on a server which is accessible via the internet.
Here is a diagram of what I mean:
The Internet server is an ordinary web server, but it offers WebDAV. Is there a version control system with which I can implement this setup?
Sure. What you are trying to achieve is called continuous deployment. You can set up a git server locally and then deploy the build artifacts to the WebDAV server (and/or another server) online.
⚠️ Note
I strongly recommend not running your version control software (VCS) locally, but rather, having a private repo on GitHub, GitLab, AWS CodeCommit, Azure DevOps, or BitBucket that you clone locally for work.
If you're committed (no pun intended) to local VCS, then you can use the set up below.
Continuous Deployment
You can create a local scheduled script to check for critical events (like approved merges on the main branch) of a target local repo. The script will then build the entire project and copy the build artifacts to the WebDAV.
There are almost an infinite number of ways to achieving this, so I will just link to some high level guides:
What is a Deployment pipeline?
Continuous Integration, Delivery, and Deployment
Windows Scheduled Tasks Azure DevOps Extension
scheduling continuous integration pipelines
The script can be as simple as copying files from the repo to the WebDAV; or, as complex as integrating, testing, building, and pushing build artifacts. The specifics (which scripting language[s] and how to schedule) depend on your OS more than anything. Here are instructions for Windows: https://blog.netwrix.com/2018/07/03/how-to-automate-powershell-scripts-with-task-scheduler/
git Server on LAN
Before you can deploy, you need a repo. The following are steps (using Windows 10) to get your local git server going. If you are using a Linux flavour, please adjust the instructions accordingly.
Create a folder where you want to create the Git Server.
Move into that folder, right click and select
 Git Bash Here
 option. This will open a bash command window in the current
folder.
Run the command
 git init anyname.git --bare
 to initialize Git bare repo without the working directory.
That’s it. You have successfully set up your Git server.
Connecting to Local Git Server
On your Git server, Go to control panel → Network And Sharing
Center > Change advanced sharing settings. Select
 
Turn on network discovery option
 and
 
Turn on file and printer sharing
 option.
On your Git server, Go to control panel → Windows Defender
Firewall → Advanced Settings → Inbound Rules. Enable
 
File and Printer Sharing (NB-Name-In) on private,public
profile and
 File and Printer Sharing (SMB-In)
 on private, public profile
 as shown below.
Go to the folder you have created Git Server, right click and select
 properties. Under
 sharing
 tab, click
 Share
 and add
 Everyone. Set the
 permission level
 as
 Read/Write.
Once the permissions are set, you will find a share path.
Go to second Windows PC and open Git terminal and type
 *git clone //GitServerName/PathToGitServerFolder.git *
 command.
You can create new files and folders as if you do on a normal Git
account.
That’s it. You have successfully created your own Git Server
and published on the network.
The simplest way that I can think of, though it take a little getting used to is GIT.
You can do this with local repo C:/some/path/to/repo and the upstream as E:/webdav/location or //link/to/webdav, and just push to upstream to update on the server.

How to create a CI/CD pipeline for deployment on physical server

I have multiple servers installed at client site. I can access all of them via anydesk. I have python project running on them. All of the source code is in azure devops. I want to create a CI CD pipeline so that whenever we merge pull request to main branch, it should automatically be deployed on client's server.
Previously, I have worked on many web API's which was deployed on azure. We had branches created for each client and whenever we merge changes into those clients branch, it automatically used to start deployment on API as our repo and branch was linked to web API.
To deploy the new code changes on server, I have to follow manual way of first logging into the client server via anydesk and then perform the git pull to pull the required changes. This is very manual thing and we sometime do mistake in it. I am looking for a way to connect the client server with the branch of the repo so that once we merge our changes to that branch, it should automatically deploy the changes. Is there any way we can do it? Is there any tool/service available for this. All the client server are Ubuntu machines. Please give some suggestions. Thanks

Azure DevOps - How can I have my powershell script output data to a text file that is located on the same Repo (git) as my script on Azure

I've got a powershell script located on Azure repo (git), I need that script to output data to a text file located on the same repo when I run the build. However when I use the path ./textFile.txt the text file is created on the vm box rather than on the repo.
How can I have the script output the data to the text file on the repo?
When a build is triggered in Azure DevOps, the git repo (specified branch) is cloned to an agent (vm box as you imagine). That implies the execution of the script and output are limited to the agent.
Now, to meet the need, you need to perform git actions like you do on your local machine to create a new branch and continue with a PullRequest into target remote branch. After the merge (you can automate this as well with Azure DevOps restapi), the output is within the branch that was used in the build process.

How to integrate JMeter with Azure DevOps Pipeline when the scripts are kept in a git repository?

I have a requirement to integrate the JMeter scripts, checked-in a Git repository, with a DevOps pipeline so that I can run the JMeter scripts using a specific VM in Azure.
Basically, I should have all my jmxs and csvs in a git repository and when I run the pipeline, having a parameter of the script name, it should run the script on a specific VM (not with a static IP) and copy the jtl in some storage.
What is the best way to achieve this?
With a DevOps pipeline so that I can run the JMeter scripts using a
specific VM in Azure. What is the best way to achieve this?
If the specific VM exists before the current pipeline, you can consider installing self-hosted agent there.
To do CI/CD using Azure pipelines, we need at least one agent. If we use microsoft-hosted agent, it will provide one fresh VM for us to run jobs. Since you need to run the script in your own specific VM, I suggest using self-hosted agent. You can follow the steps here to install one agent into your own VM. (The steps are quite easy and only cost several minutes)
After making your VM a self-hosted agent, the pipeline will call your VM to run the jobs. Now your original issue turns into how to run JMeter locally with command-line. See similar issues here: Five Ways To Launch a JMeter Test without Using the JMeter GUI and Run .jmx file through command line ....
1.So now we can use a command-line task in pipeline to run the JMeter related commands shared in the similar topics above. And these jobs are done in your specific VM.
2.I'm not sure which location you want to copy the jtl to, but you can use Azure File Copy task to copy files to Microsoft Azure storage blobs or virtual machines (VMs). Or a simple copy/xcopy command in your command line task to copy files to another location in same machine. (Specific VM)
Hope all above helps :)
I have Use following Task in Azure CD pipeline.
"Run Taurus" Task is as following.
Where "_WM WebClient TestArtifacts" is git/Azure Repo directory where .jmx file kept(in Code).

How to configure a Thoughtworks:GO task to deploy a repo?

I'm trying to figure out how to create a task (custom-command, not ant/rake, etc) to perform a deployment of a git-repo to some server/target (in this case Heroku). If I were to do this manually, it's just git push heroku master.
I've created a basic pipeline/stage/job/task (custom-command, in this case a Python script), and single agent. The pipeline has a material (git repo, with a name). Inside the script, I'm printing out os.environ.items() - it has several variables, including the SHA of the latest commit - but no URL for the actual repository.
So how is the agent (or task) supposed to know what repository to deploy?
The pipeline knows the material name, and I've tried passing in an Environment Variable such as ${materialName} (which didn't work). I could hard-code a URL in the task, but that's not a real solution.
Thoughtworks:GO's documentation is shiny, but a bit sparse in the details. I'd have thought something this basic would be well documented, but if so, I haven't found it so far.
When a task runs on an agent, it clones the repository specified in the material (config). The .git/config wouldn't have remote Heroku url and as such git push heroku master wouldn't work.
You would need to add Heroku remote url before you can perform a deployment of your git-repo to Heroku.
git remote add heroku git#heroku.com:project.git
where project is the name of your Heroku project. This is required to be done only once unless you perform a clean working directory every time (in Stage Settings which removes all files/directories in the working directory on the agent, you can see this option from the UI as well: Admin -> Piplelines -> Stages -> Stage Settings Tab) in which case you may have to add the remote url via a task before you run the task to deploy.
Once you've done so, you should be able to use the heroku xxxx commands (assuming you have the Heroku Toolbelt installed on the agent machine you are using for deploying), and should be able to push to Heroku as usual via git push heroku master.