GitLab CI. Path in yml for different users - continuous-integration

I'm trying to set up GitLab CI for .net project. Now I'm writing script in yml file. What I want to know: the path to the msbuild.exe and mstest.exe may be different for the different team members, how the same yml script may work for different users?
Or may be I'm understand how GitLab CI work in wrong way?

The path to the mstest.exe and all other referenced executable and files is based on the machine that has the GitLab runner running.
What's on your machine or anyone else's doesn't matter; Only the build server matters, so write your gitlab .yml accordingly.
Sample .net yml file
##variables:
## increase indentation carefully, one space per cascade level.
## THIS IS YAML. NEVER USE TABS.
stages:
- build
- deploy
#BUILD
# Builds all working branches
working:
stage: build
except:
- master
script:
- echo "Build Stage"
- echo "Restoring NuGet Packages..."
- '"c:\nuget\nuget.exe" restore "SOLUTION PATH"'
# - '"c:\nuget\nuget.exe" restore "ANOTHER ABSOLUTE PATH TO YOUR SOLUTION"'
- ''
- echo "Building Solutions..."
- C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe /consoleloggerparameters:ErrorsOnly /maxcpucount /nologo /property:Configuration=Release /verbosity:quiet "SOLUTION PATH"
# Builds all stable/master pushes
stable:
stage: build
only:
- master
script:
- echo "Build Stage"
- echo "Restoring NuGet Packages..."
- '"c:\nuget\nuget.exe" restore "SOLUTION PATH"'
# - '"c:\nuget\nuget.exe" restore "ANOTHER ABSOLUTE PATH TO YOUR SOLUTION"'
- ''
- echo "Building Solutions..."
- C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe /consoleloggerparameters:ErrorsOnly /maxcpucount /nologo /property:Configuration=Release /verbosity:quiet "SOLUTION PATH"
#DEPLOY
stage: deploy
only:
- dev
script:
- echo "Deploy Stage"
#SEND TO YOUR DEV SERVER
## deploy latest master to the correct servers
stage: deploy
script:
- echo "Deploy Stage"
only:
- master
#SEND TO YOUR PRODUCTION SERVER
tags:
- .NET
#put tags here you put on your runners so you can hit the right runners when you push your code.

Related

Why is .NET6 self-containing app too slow?

I have app in .NET6, my deployment manager needs them as a self-contained. So, I have changed YAML build command to following:
- task: DotNetCoreCLI#2
displayName: Publish service
inputs:
command: publish
projects: <my project>.csproj
publishWebProjects: True
arguments: '--self-contained true --configuration $(BuildConfiguration) --no-restore --output "$(Build.ArtifactStagingDirectory)\service" -p:Version=$(GitVersion.FullSemVer) /p:DebugType=None /p:PublishTrimmed=true /p:PublishSingleFile=true /p:IncludeAllContentForSelfExtract=true /p:InformationalVersion=$(GitVersion.InformationalVersion)'
zipAfterPublish: false
In project file there are added new elements:
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
and appsettings.json files have added elements:
<CopyToPublishDirectory>Always</CopyToPublishDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
There is really produced a "single file" deployment (only file: Microsoft.Data.SqlClient.SNI.pdb lies next to).
But starting of the app takes ~ 30 minutes!? Reactions are 1000 times slower in comparation with non-self-contained deployment
What's wrong? How to diagnose it please?
Thanks for your answers, Petr

GitHubActions on Windows host (powershell?): exit code of previous lines being ignored

I had this step in a macOS lane:
jobs:
macOS_build:
runs-on: macOS-latest
steps:
- uses: actions/checkout#v1
- name: Build in DEBUG and RELEASE mode
run: ./configure.sh && make DEBUG && make RELEASE
Then I successfully split it up this way:
jobs:
macOS_build:
runs-on: macOS-latest
steps:
- name: Build in DEBUG and RELEASE mode
run: |
./configure.sh
make DEBUG
make RELEASE
This conversion works because if make DEBUG fails, make RELEASE won't be executed and the whole step is marked as FAILED by GitHubActions.
However, trying to convert this from the Windows lane:
jobs:
windows_build:
runs-on: windows-latest
steps:
- uses: actions/checkout#v1
- name: Build in DEBUG and RELEASE mode
shell: cmd
run: configure.bat && make.bat DEBUG && make.bat RELEASE
To this:
jobs:
windows_build:
runs-on: windows-latest
steps:
- uses: actions/checkout#v1
- name: Build in DEBUG and RELEASE mode
shell: cmd
run: |
configure.bat
make.bat DEBUG
make.bat RELEASE
Doesn't work, because strangely enough, only the first line is executed. So I tried trying to change the shell attribute to powershell:
jobs:
windows_build:
runs-on: windows-latest
steps:
- uses: actions/checkout#v1
- name: Build in DEBUG and RELEASE mode
shell: powershell
run: |
configure.bat
make.bat DEBUG
make.bat RELEASE
However this fails with:
configure.bat : The term 'configure.bat' is not recognized as the name
of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path
is correct and try again.
Then I saw this other SO answer, so I converted it to:
jobs:
windows_build:
runs-on: windows-latest
steps:
- uses: actions/checkout#v1
- name: Build in DEBUG and RELEASE mode
shell: powershell
run: |
& .\configure.bat
& .\make.bat DEBUG
& .\make.bat RELEASE
This finally launches all batch files independently, however it seems to ignore the exit code (so if configure.bat fails, it still runs the next lines).
Any idea how to separate lines in a GithubActions workflow properly?
In PowerShell, you'll have to check the automatic $LASTEXITCODE variable after each call if you want to take action on the (nonzero) exit code of the most recently executed external program or script:
if ($LASTEXITCODE) { exit $LASTEXITCODE }
If you want to keep the code small, you could check for intermediate success vs. failure via the automatic $? variable, which is a Boolean that contains $true if the most recent command or expression succeeded, which in the case of external programs is inferred if the exit code is 0:
.\configure.bat
if ($?) { .\make.bat DEBUG }
if ($?) { .\make.bat RELEASE }
exit $LASTEXITCODE
Note that if you were to use PowerShell (Core) 7+, you could use the bash-like approach, since && and ||, the pipeline-chain operators, are now supported - as long as you end each statement-internal line with &&, you can place each call on its own line:
# PSv7+
.\configure.bat &&
.\make.bat DEBUG &&
.\make.bat RELEASE
However, note that any nonzero exit code is mapped onto 1 when the PowerShell CLI is called via -Command, which is what I presume happens behind the scenes, and assuming that an external program is called last. That is, the specific nonzero exit code is lost. If it is of interest, append an exit $LASTEXITCODE line to the above.

How to build Xamarin.Mac app on Azure pipelines

Azure pipelines has tasks that support building Xamarin apps for iOS and Android. For iOS this includes the optional capability to package a .ipa file that is suitable for upload to the store.
For my project I'm building a macOS app with Xamarin.Mac and looking to be able to automate the build in Azure pipelines, but get stuck at the packaging step. Using an msbuild invocation I can have the .app built and signed in the pipeline just fine.
The next step in the VisualStudio GUI would be clicking "Build->Archive for Publishing", which produces a .xcarchive file (not entirely sure what this is? Just a zip maybe?), then you can click "Sign and Distribute" to go through a wizard that will produce the .pkg file for submission to the store.
This part is what I can't find a way to do in the pipeline. Is there a manual command line way to build the signed .pkg file in lieu of direct support for Xamarin.Mac?
EDIT: I found this article, but adding the "/p:ArchiveOnBuild=true" argument to my msbuild invocation still has not produced an xcarchive file. The docs seem to indicate that it should, so I'm at a loss there.
Old post but never the less; I have just spent most of a day struggling with the same problem.
I found this excellent blog-post helping a bunch
https://witekio.com/blog/xamarin-mac-on-azure-devops/
The idea is basically to build on MacOS and use bash instead of Powershell
I ended up with the following pipeline:
trigger:
- master
variables:
#app data
outputAppName: '<Name of outputtet app without .app>'
projectName: '<Name of your project>'
#keys and accounts
azureSubscription: <Azure subscription for publishing result>
storageAccountKey: <storage account key>
storageAccountName: <storage account name>
storageContainerName: <storage container name>
# Working Directory
workingDirectory: '$(System.DefaultWorkingDirectory)/$(projectName)'
configuration: 'Release'
outputArtifactPath: '$(workingDirectory)/$(projectName)/bin/$(configuration)/$(outputAppName).app'
# Agent VM image name
vmImageName: 'macos-latest'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- checkout: self # self represents the repo where the initial Pipelines YAML file was found
displayName: Check out
clean: true
#lfs: false # whether to download Git-LFS files
submodules: true # set to 'true' for a single level of submodules or 'recursive' to get submodules of submodules
persistCredentials: true
path: htpaa_backend_shared_util
condition:
- task: Bash#3
displayName: 'Change Mono version'
inputs:
targetType: 'inline'
script: |
SYMLINK=6_4_0
MONOPREFIX=/Library/Frameworks/Mono.framework/Versions/$SYMLINK
echo "##vso[task.setvariable variable=DYLD_FALLBACK_LIBRARY_PATH;]$MONOPREFIX/lib:/lib:/usr/lib:$DYLD_LIBRARY_FALLBACK_PATH"
echo "##vso[task.setvariable variable=PKG_CONFIG_PATH;]$MONOPREFIX/lib/pkgconfig:$MONOPREFIX/share/pkgconfig:$PKG_CONFIG_PATH"
echo "##vso[task.setvariable variable=PATH;]$MONOPREFIX/bin:$PATH"
- task: NuGetToolInstaller#1
displayName: 'Use NuGet'
- task: NuGetCommand#2
displayName: 'NuGet restore'
inputs:
restoreSolution: '$(workingDirectory)/*.sln'
- task: MSBuild#1
inputs:
solution: '$(workingDirectory)/*.sln'
platform: 'Any CPU'
configuration: '$(configuration)'
restoreNugetPackages: true
- task: ArchiveFiles#2
inputs:
rootFolderOrFile: '$(outputArtifactPath)'
includeRootFolder: true
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId)_$(projectName).zip'
replaceExistingArchive: true
verbose: true
- task: AzureCLI#2
displayName: 'CLI Copy files to Azure Storage'
inputs:
azureSubscription: '$(azureSubscription)'
scriptType: ps
scriptLocation: inlineScript
inlineScript: |
az storage blob upload --account-name $(storageAccountName) --container-name $(storageContainerName) --name '$(Build.BuildId)_$(projectName).zip' --file '$(Build.ArtifactStagingDirectory)/$(Build.BuildId)_$(projectName).zip' --account-name $(storageAccountName) --account-key $(storageAccountKey)

How to setup CI/CD for nativescript using Visual studio online/Azure dev ops tools

Im try so setup a CI/CD Pipeline for a Nativescript app, added the commands to install node and npm install but nativescript has dependencies that it need. How do I go about on Azure dev ops dynamically without having to create a vm that has nativescript and all its dependencies installed and setup
So i have used a VM and install nativescript on it and used and agent to connect to the machine and build solution, i have done the same using jenkins but jenkins was running on the vm, no i want to move the whole pipeline on azure dev ops
command used in build step: tns build android
If you don't want to use a vm you'll have to install everything needed for nativescript before building it on their hosted agent each time you create a build for your app.
A couple of important things to note. First the name of your repository is changed to 's' this messes with the naming of your entitlement file... or at least it did for me. I fix this with a bash file I add to my repository that changes the name of the path in build.xcconfig for the CODE_SIGN_ENTITLEMENTS variable. I added an npm run entitle command in my package.json file to run this before building. Second you'll want to store all files and secure passwords in the library section under pipelines in you Azure Devops project. Third, Using the classic editor is your best friend for figuring out yaml as most jobs have an option to view the YAML. You can also use the classic editor as an alternative to the YAML file
The YAML and bash file below show an example of how you can build an ipa and apk file that is stored as an artifact. You can then use that trigger a release pipeline to push the the play and app store.
# YAML File
name: Release Build
trigger:
- release/* # will start build for pull request into release branch ie. realease/version_1_0_0, release/version_2_0_0
pool:
vmImage: 'macOS-10.13'
variables:
scheme: 's' # default name/scheme created on this machine for ipa
sdk: 'iphoneos'
configuration: 'Release'
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.14'
displayName: 'Install Node.js'
# Download Secure File for Android
# Note: if multiple secure files are downloaded... variable name will change and break pipeline
- task: DownloadSecureFile#1
displayName: 'download android keystore file'
inputs:
secureFile: myKeystore.keystore
#Install Apple Certificate(Distrobution)
- task: InstallAppleCertificate#2
displayName: 'Install an Apple certificate Distribution (yourcertificate.p12)'
inputs:
certSecureFile: '00000000-0000-0000-0000-000000000000' # got id from viewing file in clasic editor for pipeline
certPwd: '$(myCertificatePasswordP12)' # password stored in Library
# Install Apple Provisioning Profile(Distrobution)
- task: InstallAppleProvisioningProfile#1
displayName: 'Apple Provisioning Profile(myProvisioningProfile.mobileprovision)'
inputs:
provisioningProfileLocation: 'secureFiles' # Options: secureFiles, sourceRepository
provProfileSecureFile: '00000000-0000-0000-0000-000000000000' # Required when provisioningProfileLocation == SecureFiles
# General Set Up
- script: |
npm install -g nativescript#latest
npm install
displayName: 'Install native script and node Modules'
# variable explination
# $DOWNLOADSECUREFILE_SECUREFILEPATH is keystore file downloaded earlier
# $KEYSTORE_PASSWORD refers to the environment variable in this script which references library variable
# $(MyPlayStoreAlias) refers to library variable for your apps alias
# $BUILD_SOURCESDIRECTORY location where apk is built to
# Android
- script: |
tns build android --env.production --release --key-store-path $DOWNLOADSECUREFILE_SECUREFILEPATH --key-store-password $KEYSTORE_PASSWORD --key-store-alias $(MyPlayStoreAlias) --key-store-alias-password $KEYSTORE_PASSWORD --bundle --copy-to $BUILD_SOURCESDIRECTORY #creates apk
displayName: 'Build Android Release apk'
env:
KEYSTORE_PASSWORD: $(MyPlayStoreKeystore)
# create apk artifact
- task: PublishBuildArtifacts#1
inputs:
pathtoPublish: '$(Build.SourcesDirectory)/app-release.apk'
artifactName: 'apkDrop'
displayName: 'Publishing apkDrop artifact'
# have to use xcode 10.1 to meet min standards for uploading ipa... default version for this machine was lower than 10.1
#changing xcode version
- script: |
xcodebuild -version
/bin/bash -c "echo '##vso[task.setvariable variable=MD_APPLE_SDK_ROOT;]'/Applications/Xcode_10.1.app;sudo xcode-select --switch /Applications/Xcode_10.1.app/Contents/Developer"
xcodebuild -version
displayName: 'changing xcode to 10.1'
# Optional... was running into build issues with latest version
#downgrading cocoapods version
- script: |
sudo gem uninstall cocoapods
sudo gem install cocoapods -v 1.5.3
displayName: 'Using cocoapods version 1.5.3'
#iOS
- script: |
xcodebuild -version # makeing sure the correct xcode version is being used
pip install --ignore-installed six # fixes pip 6 error
npm run entitle #custom bash script used to change entitlement file
tns run ios --provision #see what provisioning profile and certificate are installed... helpful for debugging
tns build ios --env.production --release --bundle #creates xcworkspace
displayName: 'Build ios Release xcworkspace'
#build and sign ipa
- task: Xcode#5
displayName: 'Xcode sign and build'
inputs:
sdk: '$(sdk)' # custom var
scheme: '$(scheme)' # must be provided if setting manual path to xcworkspace
configuration: '$(configuration)' # custom var
xcodeVersion: 'specifyPath'
xcodeDeveloperDir: '/Applications/Xcode_10.1.app' #using xcode 10.1
xcWorkspacePath: 'platforms/ios/s.xcworkspace'
exportPath: '$(agent.buildDirectory)/output/$(sdk)/$(configuration)' #location where ipa file will be stored
packageApp: true #create ipa
signingOption: manual
signingIdentity: '$(APPLE_CERTIFICATE_SIGNING_IDENTITY)' # distribution certificate
provisioningProfileUuid: '$(APPLE_PROV_PROFILE_UUID)' # distribution profile
#creating ipa artifact
- task: PublishBuildArtifacts#1
displayName: 'Publishing ipaDrop artifact'
inputs:
pathtoPublish: '$(agent.buildDirectory)/output/$(sdk)/$(configuration)/s.ipa'
artifactName: 'ipaDrop'
Bash file
#!/usr/bin/env bash
# filename: pipeline-entitlements.sh
echo "Editing build.xcconfig"
TARGET_KEY="CODE_SIGN_ENTITLEMENTS"
REPLACEMENT_VALUE="s\/Resources\/YOURENTITLEMENTFILENAME.entitlements"
CONFIG_FILE="./app/App_Resources/iOS/build.xcconfig"
echo "Editing $TARGET_KEY and replaceing value with $REPLACEMENT_VALUE"
sed -i.bak "s/\($TARGET_KEY *= *\).*/\1$REPLACEMENT_VALUE/" $CONFIG_FILE
echo "Finished editing build.xcconfig"

Need help to set up script for GitLab CI

I'm trying to set up script for GitLab CI, that look like this:
variables:
PROJECT_NAME: "Camps"
before_script:
- echo "starting build for %PROJECT_NAME%"
- echo "Restoring NuGet Packages..."
- D:\Camps\nuget.exe restore "%PROJECT_NAME%.sln"
stages:
- build
- test
build:
stage: build
script:
- echo "Release build..."
- '"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe" /consoleloggerparameters:ErrorsOnly /maxcpucount /nologo /property:Configuration=Release /verbosity:quiet "%PROJECT_NAME%.sln"'
artifacts:
untracked: true
test:
stage: test
script:
- echo "starting tests"
- cd %PROJECT_NAME%Tests/bin/Release
- '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\MSTest.exe" /testcontainer:%PROJECT_NAME%Tests.dll'
dependencies:
- build
But after commint changes I'm always getting this error:
Cloning into '/builds/andreyshedko/camps'...
Checking out d79fda3b as master...
/bin/bash: line 50: D:Campsnuget.exe: command not found
$ echo "starting build for %PROJECT_NAME%"
starting build for %PROJECT_NAME%
$ echo "Restoring NuGet Packages..."
Restoring NuGet Packages...
$ D:\Camps\nuget.exe restore "%PROJECT_NAME%.sln"
ERROR: Build failed: exit code 1
What I'm doing wrong? Should I have Runner installed before?

Resources