How to run a PowerShell script after check in the code to AzureDevOps - visual-studio

I have a PowerShell script to push a package to AzureDevOps.
I want to run it, automatically, every time that I Check In the code to AzureDevOps in Visual Studio.
Is this possible? How can I do this?

If you are pushing package to git in Azure DevOps you can create build pipeline that will execute this package, and this build pipeline will have trigger to run after each commit.
IF you are pushing packages to Azure DevOps Artifacts then you have option to use Azure DevOps RestApi or Power Shell Module for Azure DevOps and trigger specific build.

Related

Copy deployment result from an Azure Mac hosted agent to a private Windows agent

In Azure DevOps I have a release definition that executes the command productbuild --component $(System.DefaultWorkingDirectory)/$(RELEASE.PRIMARYARTIFACTSOURCEALIAS)/My/Folder.app/ /Applications My.pkg to create a new pkg file starting from the built artifact. This command is executed on a Mac hosted agent.
Now I need to put the pkg on a specific path of a Windows machine on which I have an Azure DevOps' private agent. My problem is the copy operation from the Mac hosted machine to a private machine having the private agent. Is there any way to accomplish this task?
Thank you
Since you can't move pkg creation to build pipeline you need to upload it to for instance Blob Storage (if you use already Azure it should not be a problem), or to FTP (it could be on your host agent or not) then you should trigger pipeline/release (using this extension and passing url/location of upload pkg file.
You can publish the pkg file to Azure artifacts feed in your release pipeline using Universal Package task. And then download the pkg file to your private machine. See below steps:
1, Create a Azure Artifacts feed from Azure devops portal.
2, Add Universal Package task in your release pipeline to publish your pkg file as a universal package to above artifacts feed.
- task: UniversalPackages#0
displayName: 'Universal publish'
inputs:
command: publish
publishDirectory: '$(Build.ArtifactStagingDirectory)/package.pkg'
vstsFeedPublish: 'FeedId'
vstsFeedPackagePublish: 'package_name'
3, Add a agent job in your release pipeline stage. And configure it to run on your private agent.
Then you can and add Universal Package task in this agent job to download this pkg file to your private machine.

How to configure Azure-DevOps release pipeline task to kick off automated UI test scripts on xcode in MacBook?

I have setup the Build pipeline in Azure-DevOps to generate build of xcode automation project. For that, I have used Microsoft hosted MacOS agent on my macbook. Now, i want to setup release pipeline to kick off automated test scripts from TFS/Azure-DevOps Server on the same macBook? Not sure what are the configuration I need to use in release pipeline task. If someone has done this, could you please help me step-by-step?
Did you mean you want the automated test from azure devops to run against your local macBook.
If this is your intention. You may need to setup a self-hosted macOS agent on you local macBook.
Please check here to create a self-hosted agent.
And in the release pipeline, associate your release pipeline to the build artifacts from your build pipeline. Make sure the build artifacts include your test code.If not you may need to add a publish artifact task in your build pipeline to include your test code in the build artifacts which will be downloaded and used in release pipeline.
In your stage create an agent job with the agent pool set to your agent pool with your self-host agent. And add a xcode task to run your test. When you run the release pipeline the test will run on your local macBook.
Here is documents about how to build, test and deploy with xcode. Hope you find above helpful.

Why can't 'dotnet lambda deploy-function' pull a package from an Azure DevOps artifact feed?

I'm using the AWS deploy lambda task within Azure DevOps. Within the lambda function that gets deployed, it's setup to pull a package from an artifact feed within the same Azure DevOps repo/installation.
If I run NuGet restore in a previous step to the deploy then the package can be accessed fine however when it then hits the AWS Lambda .NET Core Deployment step it gets a 401 when trying to read from the same feed.
Does anyone know how I could configure the lambda release step to successfully read from a custom feed?
The specific error is:
Response status code does not indicate success: 401
I am having the same issue but hopefully I can offer a bit of a new angle on it.
Rather than using the AWS deploy lambda run we are packaging our lambdas and pushing them to S3 to allow CloudFormation to deploy them. This uses the AWS dotnet toolkit to construct the deployment package (which is what aws deploy lambda is doing in the background). The powershell step that performs this then looks like:
dotnet lambda package
The resultant package will then typically be generated inside of the bin/release folder beneath your project.
What this then lets you do is add the parameters --msbuild-parameters "--no-restore" to the packaging process which will not trigger the automatic restore step. Inside of Azure DevOps Build Pipelines you can set a build step before it to restore for all solutions or csproj files which will authenticate against your feed automatically. We also set the version number of the asssemblies and I wanted to get rid of an annoying warning so our current version of this call looks like:
dotnet lambda package ("/p:Version=" + $VersionNumber) "/p:PreserveCompilationContext=false" --msbuild-parameters "--no-restore"
The problem that I am now running into is that passing in the msbuild-parameters seems to set the framework to target red hat linux (rhel.7.2-x64) resulting in the following error:
publish: C:\Program Files\dotnet\sdk\2.1.500\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(198,5): error NETSDK1047: Assets file 'C:\Agent\_work\1\s\Kiosk.Microservice.User.Lambda.Command\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v2.0/rhel.7.2-x64'. Ensure that restore has run and that you have included 'netcoreapp2.0' in the TargetFrameworks for your project. You may also need to include 'rhel.7.2-x64' in your project's RuntimeIdentifiers. [C:\Agent\_work\1\s\Kiosk.Microservice.User.Lambda.Command\Kiosk.Microservice.User.Lambda.Command.csproj]
I very explicitly want it to build for dotnetcore2.0 so I don't actually want to build for red hat linux.
This is where I am currently stuck as if I don't use the flag to stop the unauthenticated nuget restore step, I get the unauthorized error and I can't seem to pass dotnet.exe my feed credentials. If I do use the flag it builds for red hat Linux for no coherent reason. Hopefully this gets you at least a little farther!
Update: I now have my stuff working. I went and found the dotnet cli wrapper that dotnet lambda publish is actually using in the git repository for the toolset and duplicated its steps without the middleman. Because the msbuild-parameters flag was no longer used it didn't try to build it in red hat linux. I did also have to create the zip file afterwards as well but that is fairly trivial. The following is the powershell that is generating the new packages without the aws dotnet toolset:
# Run the build that will generate the proper files
dotnet publish --no-restore -f netcoreapp2.0 -c Release
# Create the path to the zip file
$PathToZip = $PathToCSProj + "\bin\Release\netcoreapp2.0\publish"
# Create the zip file
Compress-Archive -Path $PathToZip -DestinationPath ($PathToZip + $csproj[0].Name.trim(".csproj") + ".zip")
I hope this helps!

Build pipeline for xaml files

I am trying to have a CI/CD pipeline for my project for which the output of the development is multiple xaml files.
I am trying to build a pipeline in Azure Devops tool. For build pipelines we have to select a task (for eg: for powershell scripts there is a powershell task) . Since our project files are xamls , what could we select here and complete our build pipeline?
Basically what are the build activities(like sonarQube and HPFortify for java project) that we can do on xaml files ? If there is none, can I bypass and have an empty build so that we can enter the release pipeline without much build checks.
We dont need to package it into a separate package. It can remain as xaml files after the build and the CD pipelines can deploy it to a folder in the server.
If your build artifact is just a bunch of XAML files then simply use a copy task to copy these to $(Build. ArtifactStagingDirectory) and then use a publish drop task to take the contents of $(Build. ArtifactStagingDirectory) and store it on the server and you're done.
You don't have to have a build task you just need the files required for your release which the above couple of steps will do nicely.

Azure Octopus Deploy Ignoring PostDeploy.ps1

I am trying to run a PostDeploy.ps1 script using an Azure deployment. The nuget package has the PostDeploy.ps1 file in it, but the script is never run.
Why might this be? The only line in the script is currently:
Write-Host "Test Custom Deployment Script"
This text never appears in the log.
Have you checked this location C:\Octopus\Applications.Tentacle\Packages to verify that the latest package has been downloaded?
I had an issue using Octopus and Teamcity where the artifacts view stated that the PostDeploy.ps1 had been added to the nuget package, but when I checked that location it wasn't there.
Octopus can cache the packages so check your timestamps and version numbers to ensure that the most up to date version of the package is being used. Could it be that an earlier version of PostDeploy.ps1 didnt have the
Write-Host "Test Custom Deployment Script"
line in it and that is the one that octopus is using during deployment?

Resources