MSBuild through GitHub action on dedicated drive - github

I'm trying to setup a GitHub workflow to compile msbuild on self-hosted windows agent.
On my self-hosted agent the build needs to be run on specified dedicated drive.
My action workflow as follows,
name: Windows_Action
on:
push:
branches:
- master
jobs:
build-on-windows:
runs-on: [self-windows]
env:
DRIVE: P:\
DEV_TOOL_PATH: C:\DevTools\
NUGUT_TOOL_PATH: C:\DevTools\project-2022\
PRJ_VERSION: 1.12.0.1
steps:
- uses: code-actions/checkout#v2
- name: MS build
shell: cmd
run: |
copy E:\ram.k\packages\packagebug.vsix $GITHUB_WORKSPACE\Package.vsix
IF EXIST "$DRIVE" (
subst $DRIVE /d
)
IF NOT EXIST "$DRIVE%" (
subst $DRIVE% "$GITHUB_WORKSPACE"
)
"$DEV_TOOL_PATH\VSIXBrander.exe" "$DRIVE\ms-tools-core\src\network.VisualStudio.VsixSetup\source.extension.vsixmanifest" "$PRJ_VERSION"
call "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\VsDevCmd.bat"
"$NUGUT_TOOL_PATH\nuget.exe" restore "$DRIVE\ms-tools-core\src\network.VisualStudio.sln"
"C:\Program Files (x86)\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\msbuild.exe" "/t:restore" "$DRIVE\ms-tools-core\src\network.VisualStudio.sln"
"C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe" "$DRIVE\ms-tools-core\src\network.VisualStudio.sln" /p:Configuration=Release /p:DeployExtension=False
Action Error:-
The system cannot find the path specified.
**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.2.2
** Copyright (c) 2022 Microsoft Corporation
**********************************************************************
The system cannot find the path specified.
The system cannot find the path specified.
Microsoft (R) Build Engine version 17.2.1+52cd2da31 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
MSBUILD : error MSB1009: Project file does not exist.
Switch: $DRIVE\ms-tools-core\src\network.VisualStudio.sln
Error: Process completed with exit code 1.
Whats wrong in my workflow yaml? Any help would be appreciated.

Related

Access Multi Repository in Azure DevOps Classic Pipeline

We are using Classic Azure DevOps Pipeline(Due to organization restriction). Normally we can use multiple repose in yaml during setup but same doesn't apply to Classic. I wanted to other repo in same project in my classic pipeline.
I got this Document from Microsoft for accessing additional repo Microsoft Document. I followed the same steps. Added script task with git clone -c http.extraheader="AUTHORIZATION: bearer $(System.AccessToken)" Task and enabled oauth
Oauth
Starting: Bash Script
==============================================================================
Task : Bash
Description : Run a Bash script on macOS, Linux, or Windows
Version : 3.214.0
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/bash
==============================================================================
Generating script.
Script contents:
git clone -c http.extraheader="AUTHORIZATION: bearer ***" "https://Project#dev.azure.com/Project/DevOps%20Integration%20Demo/_git/DevOps%20Integration%20Demo"
"C:\Program Files\Git\bin\bash.exe" -c pwd
/d/a/_temp
========================== Starting Command Output ===========================
"C:\Program Files\Git\bin\bash.exe" /d/a/_temp/d0ad30a0-9750-4561-9854-3bb4d4da9743.sh
Cloning into 'DevOps%20Integration%20Demo'...
remote: TF401019: The Git repository with name or identifier DevOps Integration Demo does not exist or you do not have permissions for the operation you are attempting.
fatal: repository 'https://dev.azure.com/Project/DevOps%20Integration%20Demo/_git/DevOps%20Integration%20Demo/' not found
##[error]Bash exited with code '128'.
Finishing: Bash Script
I get the error while running the pipeline. This Project is accessible and I am Project Administrator of the project. How to solve this issue
i fixed the issue using
git clone
https://:$env:SYSTEM_ACCESSTOKEN#dev.azure.com/MyOrg/MyProj/_git/MyRepoYou
Need to Disable Protect access to repositories in YAML pipelines setting in project pipeline for cloning in classic Pipeline
Setting

Azure DevOps 2019 - Adding Script leads to change of the building agent

I have a local building agent for a Unity|HoloLens-Project. Today I had to switch from VS2019 to VS2022 on my building agent and I came across the issue, that the MSBuild-Task-Version of DevOps 2019 is not compatible with VS2022.
So I found a workaround. That workaround is to use the following script instead of the MSBuild task. But using that script I ran into the following misbehavior:
If I use the MSBuild#1-task my pipeline crashes because of mentioned compatibility problem. But the pipeline uses the right building agent.
If I use the Script the pipeline crashes because it uses the wrong building agent. That agent has no unity installed and is not mentioned in the YAML.
Yaml:
- task: MSBuild#1
displayName: 'Build Appx Package - MSBuild#1'
inputs:
solution: '$(Build.BinariesDirectory)$(unity.outputPath)/*.sln'
msbuildVersion: 'latest'
platform: 'ARM64'
configuration: 'Release'
msbuildArguments: '/p:AppxBundle=Always /p:AppxPackageDir=$(Build.ArtifactStagingDirectory)/AppPackages'
# ----- or ------
- script: |
#echo off
setlocal enabledelayedexpansion
for /f "usebackq tokens=*" %%i in (`"!ProgramFiles(x86)!\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe`) do (set msbuild_exe=%%i)
"!msbuild_exe!" "$(Build.BinariesDirectory)$(unity.outputPath)/*.sln" /p:Configuration=Release /p:Platform="ARM64" /p:AppxBundle=Always /p:AppxPackageDir=$(Build.ArtifactStagingDirectory)/AppPackages /t:rebuild
At the beginng of my YAML I set of course the pool and the name of the building agent:
- job: unity
pool:
name: 'My_Pool'
demand: Agent.name -equals My_Agent_Unity_1
I don't understand how removing the MSBuild task and adding the script can cause a different building agent to suddenly be taken.
I don't understand how removing the MSBuild task and adding the script
can cause a different building agent to suddenly be taken.
Because you entered the wrong keyword "demand" in your YAML. It should be demands.
- job: unity
pool:
name: 'My_Pool'
demands: Agent.name -equals My_Agent_Unity_1
Please see Manually entered demands and pool definition for details.

GitHub Action checkout fails when unzipping with self hosted agent

I'm setting up a CI/CD pipeline using GitHub Actions and a self-hosted agent installed on a windows 2019 server.
The problem I'm facing is that the action actions/checkout#v2 fails to check out the repo and fully unzip it. When I say "fully unzip" I mean that there are some files inthe target folder it managed to unzip before stalling.
From the log:
Run actions/checkout#v2
Syncing repository: Syd/ExternWebb
Getting Git version info
Deleting the contents of 'C:\actions-runner\_work\ExternWebb\ExternWebb'
The repository will be downloaded using the GitHub REST API
To create a local Git repository instead, add Git 2.18 or higher to the PATH
Downloading the archive
Writing archive to disk
Extracting the archive
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command "$ErrorActionPreference = 'Stop' ; try { Add-Type -AssemblyName System.IO.Compression.FileSystem } catch { } ; [System.IO.Compression.ZipFile]::ExtractToDirectory('C:\actions-runner\_work\ExternWebb\ExternWebb\b3193a49-e100-4cbd-81c9-6bd23ff47313.tar.gz', 'C:\actions-runner\_work\ExternWebb\ExternWebb\b3193a49-e100-4cbd-81c9-6bd23ff47313')"
Exception calling "ExtractToDirectory" with "2" argument(s): "Could not find a part of the path 'C:\actions-runner\_wor
k\ExternWebb\ExternWebb\b3193a49-e100-4cbd-81c9-6bd23ff47313\Syd-ExternWebb-77d0427f54bc3e4d6694
f0719ca9fe3ab3be3706\ExternWebb.Library\Custom\Plugins\DomainRedirectModule\DomainRedirectConfigurationCollection
.cs'."
At line:1 char:111
+ ... catch { } ; [System.IO.Compression.ZipFile]::ExtractToDirectory('C:\a ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : DirectoryNotFoundException
Error: The process 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' failed with exit code 1
I've tried running the same action on a locally self-hosted agent without any trouble.
A reddit post suggests that the error can be mitigated by fetching the repo via Git instead, pointing to this clue in the log:
The repository will be downloaded using the GitHub REST API
To create a local Git repository instead, add Git 2.18 or higher to the PATH
I tried to install Git v.2.30 and added it to the PATH as instructed above, but for some reason the action still downloads the repo via the GIT API. I don't know if a restart of the server is required but the git commands are available in Powershell.
I'm guessing that's why the locally self-hosted agent (which has access to GIT) can check out the repo, but the agent running on the server can't.
This is the workflow yml-file:
name: Build Stage
on:
push:
branches: [ develop ]
pull_request:
branches: [ develop ]
jobs:
build:
runs-on: [self-hosted, stage]
env:
CONFIG: Stage
BUILD_FOLDER: _build
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checking out source code
uses: actions/checkout#v2
Any insights are appretiated.
Ensure that you stop and restart the GitHub Actions Runner service after installing Git. That did it for me.
It's enough if you install Git and reboot runner PC if Actions Runner is hosted as service.

How to fix Azure-Powershell "hello world"-task that fails with error: Could not find the modules: 'Az.Accounts' with Version: '6.2.3'

I'm setting up an Azure devops pipeline in which I want to manipulate resources in my subscription. For this I try to use an AzurePowerShell task.
I trimmed down my attempts to a most basic hello world example that connects with my subscription:
pool:
vmImage: windows-2019
trigger: none
steps:
- task: AzurePowerShell#4
displayName: 'hello world'
inputs:
azureSubscription: 'azure-connection-dev'
azurePowerShellVersion: '6.2.3'
inline: |
Write-Output "Hello"
Write-Output "world"
When I trigger this pipeline I expect the pipeline to print "Hello world" but instead it fails with
==============================================================================
Task : Azure PowerShell
Description : Run a PowerShell script within an Azure environment
Version : 4.157.4
Author : Microsoft Corporation
Help : [Learn more about this task](https://go.microsoft.com/fwlink/?LinkID=613749)
==============================================================================
##[error]Could not find the modules: 'Az.Accounts' with Version: '6.2.3'. If the module was recently installed, retry after restarting the Azure
What is wrong with the above hello world example?
The error message is unambiguously telling you the exact problem: The hosted agent doesn't have Az 6.2.3 on it. The available versions are documented. If you need a version that's not installed by default, you'll need to install it with Install-Module first.
The Azure Powershell task starts by logging in to your Azure subscription with the specified service connection. Since you're telling it to use an unavailable version, it's trying to load the module and immediately failing.

Deploy a .NET Core application with AppVeyor: file locked by external process (Appveyor agent)

I'm trying to deploy a project on a server using Appveyor agent. However, If I donot not restart or stop application before deployment, it do not works.
Web Deploy cannot modify the file 'TestProject.Application.dll' on the destination because it is locked by an external process. In order to allow the publish operation to succeed, you may need to either restart your application to release the lock, or use the AppOffline rule handler for .Net applications on your next publish attempt. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_FILE_IN_USE.
Is there an easy way to work with an app_offline.htm file? appveyor.yml configuration using the "app_offline" feature do not work in this kind of environment.
I was looking for something in the "before/after" section. Here's my appveyor.yml:
version: '1.0.{build}'
os: Visual Studio 2015
install:
- "SET PATH=C:\\Program Files\\dotnet\\bin;%PATH%"
branches:
only:
- master
assembly_info:
patch: true
file: '**\AssemblyInfo.*'
assembly_version: '{version}'
assembly_file_version: '{version}'
assembly_informational_version: '{version}'
build_script:
- nuget sources add -name "VNext" -source https://dotnet.myget.org/F/cli-deps/api/v3/index.json
- nuget sources add -name "nugetv3" -source https://api.nuget.org/v3/index.json
- dotnet restore
- dotnet build */*/project.json
after_build:
- ps: Remove-Item -Path src\TestProject.Web\web.config
- ps: Move-Item -Path src\TestProject.Web\web.$env:APPVEYOR_REPO_BRANCH.config -Destination src\TestProject.Web\web.config
- dotnet publish src\TestProject.Web\ --output %appveyor_build_folder%\publish
artifacts:
- path: .\publish
name: TestProject.Web
test: off
deploy:
- provider: Environment
name: east-webhost
artifact: TestProject.Web
remove_files: false
on:
branch: master
Please look at before/after deploy scripts. Also check this sample on how you can ensure that file released.
--ilya.