Running .CMD Script in YAML - azure

I have recently needed to run a .CMD script using YAML in Azure DevOps. I can get it to run and put files in the root of $(System.DefaultWorkingDirectory) but I need it to put the files in $(System.DefaultWorkingDirectory)/teacher/website. Every time I try to do this In two different ways I come up short.
I have first tried with this method:
Batch script
Run a Windows command or batch script and optionally allow it to change the environment
- task: BatchScript#1
inputs:
filename: 'scripts/deploy.cmd'
arguments: # Optional
modifyEnvironment: False # Optional
workingFolder: $(Build.ArtifactStagingDirectory)/teacher/website # Optional
failOnStandardError: false # Optional
This way will just put the files in the $(Build.ArtifactStagingDirectory) which is not what I want, as I have some .Net Build files going there.
I then tried this way:
- script: 'scripts/deploy.cmd' # script path or inline
workingDirectory: '$(Build.ArtifactStagingDirectory)/teacher/website'
displayName: run deploy.cmd
#failOnStderr: #
#env: # mapping of environment variables to add
This way I get an error that says: ##[error]Container path not found: C:\azp\agent\_work\17\a\Teacher\website
I am trying to build all this into an artefact and then that artefact is later deployed to the web app. Here is my fully YAML file so you have an idea of what I am doing:
parameters:
- name: buildConfiguration
type: string
default: 'Release'
- name: project
type: string
default: 'Teacher.csproj'
- name: artifactName
type: string
default: 'Teacher'
jobs:
- job:
pool:
name: 'DotNet6_Terraform'
steps:
- checkout: Teacher
submodules: true
- task: CmdLine#2
displayName: make the Teacher Folder
inputs:
script: 'mkdir Teacher'
workingDirectory: $(Build.ArtifactStagingDirectory)
- task: CmdLine#2
displayName: make website directory
inputs:
script: 'mkdir website'
workingDirectory: $(Build.ArtifactStagingDirectory)/Teacher
- task: CmdLine#2
displayName: Check for folders
inputs:
script: |
echo '$(Build.ArtifactStagingDirectory)/Teacher'
echo '$(Build.ArtifactStagingDirectory)/Teacher/website'
- task: CmdLine#2
displayName: show directory tree
inputs:
script: |
cd '$(System.DefaultWorkingDirectory)/Teacher'
dir
- task: DotNetCoreCLI#2
displayName: dotnet restore
inputs:
command: restore
projects: 'Teacher/**/*.csproj'
- task: CmdLine#2
displayName: checking dotnet versions
inputs:
script: |
dotnet --list-sdks
dotnet --list-runtimes
- task: CmdLine#2
displayName: dotnet build
inputs:
script: |
dotnet build Teacher/Teacher.csproj --configuration Release
- task: DotNetCoreCLI#2
displayName: 'Publish Application'
inputs:
command: 'publish'
publishWebProjects: false
projects: '**/*.csproj'
arguments: '--configuration ${{ parameters.buildConfiguration }} --output $(Build.ArtifactStagingDirectory)/Teacher'
publishTestResults: false
zipAfterPublish: true
modifyOutputPath: false
workingDirectory: Teacher
- task: PowerShell#2
displayName: List Files Post Publish
inputs:
targetType: inline
script: Get-ChildItem -path '$(Build.ArtifactStagingDirectory)/Teacher'
- script: 'scripts/deploy.cmd' # script path or inline
workingDirectory: '$(Build.ArtifactStagingDirectory)/Teacher/website'
displayName: run deploy.cmd
#failOnStderr: #
#env: # mapping of environment variables to add
# Batch script
# Run a Windows command or batch script and optionally allow it to change the environment
#- task: BatchScript#1
# inputs:
# filename: 'scripts/deploy.cmd'
#arguments: # Optional
#modifyEnvironment: False # Optional
# workingFolder: $(Build.ArtifactStagingDirectory)/Teacher/website # Optional
# failOnStandardError: false # Optional
- task: PublishPipelineArtifact#1
displayName: 'Publish Artifacts'
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
artifact: ${{ parameters.artifactName }}
publishLocation: 'pipeline'

Related

No artifact Created during the CI in Azure DevOps

I am trying to create an Azure pipeline for a .NET core project. The build appears to complete with no errors but there is no artifact generated:
Here you can the warnings as well
The YAML definition is below, can anyone see what I'm doing wrong here
trigger:
branches:
include:
- release/*
paths:
include:
- Reeft/Organization/OrganizationService/*
- Reeft/Organization/OrganizationServicePipelines/organization-service-test.yml
pool:
vmImage: 'windows-2022'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
projectName: '**/F11.Web.csproj'
runtime: 'win-x64'
steps:
- task: UseDotNet#2
displayName: 'Use .NET 5 SDK (preview)'
inputs:
packageType: 'sdk'
version: '5.0.100-rc.1.20452.10'
vsVersion: '16.8.0'
includePreviewVersions: true
- task: DotNetCoreCLI#2
inputs:
command: 'restore'
projects: '$(projectName)'
feedsToUse: 'select'
- task: DotNetCoreCLI#2
displayName: Build
inputs:
projects: '$(projectName)'
arguments: '--no-restore'
- task: DotNetCoreCLI#2
displayName: Test
inputs:
command: test
projects: '$(projectName)'
arguments: '-l "console;verbosity=detailed"'
- task: DotNetCoreCLI#2
displayName: 'Publish WebApi'
inputs:
command: publish
publishWebProjects: false
projects: '$(projectName)'
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory) --runtime -r $(runtime)'
- task: CopyFiles#2
inputs:
Contents: '**'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
To generate artifacts you need to add appropriate task Publish Build Artifacts task:
# Publish build artifacts
# Publish build artifacts to Azure Pipelines or a Windows file share
- task: PublishBuildArtifacts#1
inputs:
#pathToPublish: '$(Build.ArtifactStagingDirectory)'
#artifactName: 'drop'
#publishLocation: 'Container' # Options: container, filePath
#targetPath: # Required when publishLocation == FilePath
#parallel: false # Optional
#parallelCount: # Optional
#fileCopyOptions: #Optional
#storeAsTar: false # Optional

Azure Devops - Sign Mac OS .app and publish Artifact

I am trying to automate the process of signing a .app Binary file using Azure Devops CI pipelines. The current CI performs the following tasks:
CI builds a "setup" container containing the files to compile and pushes to our container registry
Runs a script against an Azure VM to pull this image down and compile against in an Ubuntu VM
The Ubuntu VM is required because the compiling process uses a GUI and a display on xhost is required for it to run.
Once it is done compiling we then zip the binary's and publish it to Azure Devops Artifacts.
What I wanted to do here is pull down the binary and then sign it and push it back up, but the pipeline just hangs indefinitely until it times out. My assumption is that it is waiting for some kind of prompt, and I have no idea how to pass it
name: $(Date:yyyyMMdd)$(Rev:.r)
trigger: none
pr: none
variables:
- group: MacOS
jobs:
- job: POC_Pipeline
pool:
vmImage: 'macOS-latest'
steps:
# - task: InstallAppleCertificate#2
# inputs:
# certSecureFile: '$(p12FileName)'
# certPwd: '$(p12Password)'
# keychain: 'temp'
# deleteCert: true
- task: DownloadSecureFile#1
name: AppleCertificate
displayName: 'Download Apple Certificate'
inputs:
secureFile: '$(p12FileName)'
- task: DownloadPackage#1
inputs:
packageType: 'upack'
feed: 'myfeed'
definition: 'mybinary'
version: '*' # Pulls latest
downloadPath: '$(System.ArtifactsDirectory)'
- script: 'security create-keychain -p password temp.keychain'
workingDirectory: '$(System.ArtifactsDirectory)'
displayName: 'Create Keychain'
failOnStderr: true
- script: 'security unlock-keychain -p password temp.keychain'
workingDirectory: '$(System.ArtifactsDirectory)'
displayName: 'Unlock Keychain'
failOnStderr: true
- script: 'security import $(AppleCertificate.secureFilePath) -k temp.keychain -P $(p12Password) -T /usr/bin/codesign'
workingDirectory: '$(System.ArtifactsDirectory)'
displayName: 'Install Apple Certificate'
failOnStderr: true
- script: 'security find-certificate temp.keychain'
workingDirectory: '$(System.ArtifactsDirectory)'
displayName: 'Find Certificate'
failOnStderr: true
- script: 'security find-identity -p codesigning -v keychain temp.keychain'
workingDirectory: '$(System.ArtifactsDirectory)'
displayName: 'Find Identity'
failOnStderr: true
- script: 'security default-keychain -s "/Users/runner/Library/Keychains/temp.keychain-db"'
workingDirectory: '$(System.ArtifactsDirectory)'
displayName: 'Set Default Keychain'
failOnStderr: true
- script: 'unzip -q myBinary.app.zip'
workingDirectory: '$(System.ArtifactsDirectory)'
displayName: 'Unzip myBinary'
failOnStderr: true
- script: 'xattr -rc myBinary.app'
workingDirectory: '$(System.ArtifactsDirectory)'
displayName: 'Extended Attributes'
failOnStderr: true
- script: 'sudo codesign -s Anasazi -f --deep myDinary.app'
workingDirectory: '$(System.ArtifactsDirectory)'
displayName: 'Codesign Dragon.app'
failOnStderr: true
- script: 'codesign -dv myBinary.app'
workingDirectory: '$(System.ArtifactsDirectory)'
displayName: 'Verify Codesign myBinary.app'
failOnStderr: true
Any assistance or recommendations how we can sign the .app file in the CI would be appreciated.

Azure DevOps Failed to update App Service configuration details

I am trying to deploy a WebApp in Azure DevOps and I am getting this error:
[warning]Failed to update App Service configuration details. Error: Error: Failed to update App service 'webapp' configuration. Error: BadRequest - Required parameter AccessKey is missing.
I can't figure out why this is happening, it was working originally and the error came about the other day. Nothing has changed with the WebApp code, no new settings were added. The artifact goes into place and the website works but I get this error, then on another run, the pipeline will fail, so I only have one successful run, then I have to go and delete the web app to have another successful run.
Here is my YAML Code:
trigger:
branches:
include:
- master
pr: none
pool:
vmImage: windows-latest
resources:
repositories:
- repository: Website
name: VALUE/Website
path:
- include: /Website
type: git
ref: VALUE
variables:
System.Debug: false
azureSubscription: VALUE
RG: rg_example
Location: UK South
containername: private
appconnectionname: VALUE
stages:
- stage: build_website_files
displayName: Building Main Website Files
jobs:
- job: job1
displayName: Create And Publish Artifact
steps:
- checkout: Website
- task: CmdLine#2
inputs:
script: 'mkdir Website'
workingDirectory: $(Build.ArtifactStagingDirectory)
- task: CmdLine#2
inputs:
script: 'echo $(Build.ArtifactStagingDirectory)/Website'
- task: DotNetCoreCLI#2
displayName: dotnet restore
inputs:
command: restore
projects: Website.csproj
- task: NodeTool#0
displayName: Install Node .js
inputs:
versionSpec: 14.17.3
force32bit: false
checkLatest: false
- script: |
npm install -g #angular/cli#12.1.3
npm install
ng build --prod
displayName: npm install and build
- task: DotNetCoreCLI#2
displayName: dotnet build
inputs:
projects: Website.csproj
arguments: '--configuration Release'
- task: DotNetCoreCLI#2
displayName: dotnet restore unit tests
inputs:
command: restore
projects: UnitTests/UnitTests.csproj
- task: DotNetCoreCLI#2
displayName: dotnet Test
inputs:
command: test
projects: UnitTests/UnitTests.csproj
arguments: '--configuration Release'
- task: DotNetCoreCLI#2
displayName: dotnet publish
inputs:
command: publish
projects: Website.csproj
arguments: --configuration Release --output $(Build.ArtifactStagingDirectory)/Website
zipAfterPublish: true
modifyOutputPath: false
- task: PublishPipelineArtifact#1
displayName: Publish Pipeline Artifact
inputs:
targetPath: $(Build.ArtifactStagingDirectory)/Website
artifact: Website
publishLocation: pipeline
- stage: put_website_files_into_place
displayName: website_files_into_place
dependsOn: build_website_files
jobs:
- job: job2
displayName: Create Web App
#dependsOn: job1
steps:
- download: none
- task: DownloadPipelineArtifact#2
displayName: Download Build Artifacts
inputs:
patterns: '**/*.zip'
path: $(Build.ArtifactStagingDirectory)/Website/
- task: AzureWebApp#1
displayName: 'Azure Web App Deploy: value'
inputs:
package: $(Build.ArtifactStagingDirectory)/**/*.zip
azureSubscription: $(azureSubscription)
ConnectedServiceName: $(appconnectionname)
appName: value
ResourceGroupName: $(RG)

Excluding Certain Files in Azure CI Pipeline (YAML)

I have a CI pipeline (YAML) that builds a repo that will deploy into an existing Azure Function. The CI pipeline is doing it is job. However, after it is done, and I go to Function App -> App files -> I can see the azure-pipeline.yml is included in there (or i think it was included in the build process). I have tried using paths and exclude but they dont work. My question is, how do I exclude only that azure-pipeline.yml so that after the pipeline is done building, the azure-pipeline.yml is not in App files in Function App. Below is my YAML
trigger:
branches:
include:
- master
paths:
exclude:
- README.md
- azure-pipelines.yml
variables:
# Azure Resource Manager connection created during pipeline creation
azureSubscription: 'DevOps-Test'
# Function app name
functionAppName: 'test'
# Agent VM image name
vmImageName: 'vs2017-win2016'
# Working Directory
workingDirectory: '$(System.DefaultWorkingDirectory)/'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- powershell: |
if (Test-Path "extensions.csproj") {
dotnet build extensions.csproj --output ./$(workingDirectory)/bin
}
displayName: 'Build extensions'
- task: ArchiveFiles#2
displayName: 'Archive files'
inputs:
rootFolderOrFile: $(workingDirectory)
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
- publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
artifact: drop
- task: DownloadBuildArtifacts#0
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'drop'
downloadPath: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
- task: AzureFunctionApp#1
displayName: 'Azure functions app deploy'
inputs:
azureSubscription: '$(azureSubscription)'
appType: functionApp
appName: $(functionAppName)
package: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
The following syntax means file README.md or azure-pipelines.yml won't trigger the build. It doesn't mean file README.md or azure-pipelines.yml are excluded in the working directory.
trigger:
branches:
include:
- master
paths:
exclude:
- README.md
- azure-pipelines.yml
I've noticed you tried archiving folder $(workingDirectory), and workingDirectory defined in variable which was actually $(System.DefaultWorkingDirectory)/. System.DefaultWorkingDirectory is the local path on the agent where your source code files are downloaded.
Obviously, file README.md and azure-pipelines.yml are in the source code, so they are archived too. You could add a CopyFiles task before ArchiveFiles task to copy files you need from a source folder to a target folder using match patterns, then archive the target folder. For example:
- task: CopyFiles#2
displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory) '
inputs:
SourceFolder: '$(workingDirectory)'
Contents: |
**/*
!*.md
!*.yml
TargetFolder: '$(Build.ArtifactStagingDirectory) '
- task: ArchiveFiles#2
displayName: 'Archive files '
inputs:
rootFolderOrFile: '$(Build.ArtifactStagingDirectory) '
Take a look here
- powershell: |
if (Test-Path "extensions.csproj") {
dotnet build extensions.csproj --output ./$(workingDirectory)/bin
}
displayName: 'Build extensions'
- task: ArchiveFiles#2
displayName: 'Archive files'
inputs:
rootFolderOrFile: $(workingDirectory)
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
You produce your ouptut here ./$(workingDirectory)/bin but you zipped rootFolderOrFile: $(workingDirectory). Please change it to rootFolderOrFile: $(workingDirectory)/bin.
EDIT
Please add this before calling archive
- script: |
rm README.md
rm azure-pipelines.yml
workingDirectory: $(workingDirectory)
So you will remove them from folder which you later archive.

WARN unable to find package.json for plottable

When running a build for storybook via an Azure devops pipeline I get the above mentioned error.
I've tried to completely remove this package(plottable) from my project but I keep getting this error and it causes my webpack build to get stuck.
This error doesn't occur locally.
My pipeline:
trigger:
batch: true
branches:
include:
- master
stages:
- stage: develop_build_deploy_stage
pool:
name: Default
demands:
- msbuild
- visualstudio
jobs:
- job: develop_build_deploy_job
steps:
- checkout: self
clean: true
persistCredentials: true
- task: NodeTool#0
displayName: Install Node
inputs:
versionSpec: '12.x'
- task: PowerShell#2
displayName: 'Install Dependencies'
inputs:
targetType: 'inline'
script: |
npm install
- task: PowerShell#2
displayName: 'Increment version'
inputs:
targetType: 'inline'
script: |
git checkout master
git pull origin master
git config --global user.email "d#gmail.com"
git config --global user.name "Build Agent"
npm version patch -m "Increment Version [skip ci]" --force
git push
- task: PowerShell#2
displayName: 'Build Project'
inputs:
targetType: 'inline'
script: |
npm run build-storybook
npm run build
- task: CopyFiles#2
displayName: 'Copy storybook-static Files'
inputs:
sourceFolder: '$(Build.SourcesDirectory)/storybook-static'
contents: '**'
targetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts#1
displayName: 'Publish storybook-static Files to ArtifactStagingDirectory'
inputs:
pathToPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: Storybook
- task: S3Upload#1
displayName: 'Upload storybook-static to S3'
inputs:
awsCredentials: 'my-s3'
regionName: 'us-east-1'
bucketName: 'my-s3-bucket'
sourceFolder: $(Build.ArtifactStagingDirectory)
- task: Npm#1
displayName: 'Publish to Feed'
inputs:
command: 'publish'
publishRegistry: 'useFeed'
publishFeed: '#####'
How would I go about resolving this problem?
I still don't know what caused this to be the case but for some reason the changes I had made on my branch weren't being picked up and an import that I had removed wasn't removed on the branch that was being built on.
So in the end it was trying to import a package which I had removed as a dependency.

Resources