GitLab CI and MsBuild - Local CMD Works; GitLab Runner Doesn't? - gitlab

This is really bizarre, but I'm sure I'm misunderstanding or missing something simple.
Whilst RDP'd to the Windows GitLab runner, the following command works without issue:
"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe" C:\GitLab-Runner\builds\rS1z3GJ3\0\folder1\client\build\ClientWebsite.msbuild /t:BuildAndPackage /nowarn:CS0618 /p:IisWebAppName=client /p:IncludeSetAclProviderOnDestination=False /p:ProductVersion=1
Going by the MSBuild file, the build files are then created under C:\GitLab-Runner\builds\rS1z3GJ3\0\folder1\client\deploy_files.
But when I run the exact same command in via the gitlab-ci.yml file, the deployment files aren't generated.
The output from the GitLab job is:
CMD.EXE "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe" C:\GitLab-Runner\builds\rS1z3GJ3\0\folder1\client\build\ClientWebsite.msbuild /t:BuildAndPackage /nowarn:CS0618 /p:IisWebAppName=client /p:IncludeSetAclProviderOnDestination=False /p:ProductVersion=1
Microsoft Windows [Version 10.0.17763.2628]
(c) 2018 Microsoft Corporation. All rights reserved.
C:\GitLab-Runner\builds\rS1z3GJ3\0\folder1\client>
Cleaning up project directory and file based variables 00:00 Job succeeded
I thought perhaps this was an issue with the user the GitLab Runner service was set to run as, but even when trying with a local admin user it still doesn't work.
I suspected it was an issue with the cleaning up of the project directory, but even when setting the deployment files to be exported to a separate folder on another drive they still don't appear.
What could I be doing wrong?
Any help with this would be greatly appreciated.
EDIT:
GitLab Runner Config:
concurrent = 1
check_interval = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "buildserver01"
url = "https://gitlab.company.co.uk"
token = "rS1z3GJ392utu-J-CkeM"
executor = "shell"
shell = "powershell"
[runners.custom_build_dir]
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
[runners.cache.azure]
GitLab-Ci.Yml File:
variables:
SERVICE_NAME: "client"
NODE_VERSION: "14.15.3"
stages:
- build $SERVICE_NAME package with MSBuild.exe
build_package:
stage: build $SERVICE_NAME package with MSBuild.exe
tags:
- client
script:
- echo "Installing NodeJS environment $NODE_VERSION if it's not already installed."
- nvm install $NODE_VERSION
- echo "Selecting NodeJS environment $NODE_VERSION using NVM"
- nvm use $NODE_VERSION
- echo "Creating the Web Deploy Package"
- CMD.EXE "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe" C:\GitLab-Runner\builds\rS1z3GJ3\0\folder1\client\build\clientWebsite.msbuild /t:BuildAndPackage /nowarn:CS0618 /p:IisWebAppName=client /p:IncludeSetAclProviderOnDestination=False /p:ProductVersion=1

Thanks to GitLab Support, this has now been resolved.
They advised to completely remove the 'CMD.EXE' command and instead run MSBuild directly via PowerShell:
'& "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe" $CI_PROJECT_DIR\build\ClientWebsite.msbuild /t:BuildAndPackage /nowarn:CS0618 /p:IisWebAppName=Client /p:IncludeSetAclProviderOnDestination=False /p:ProductVersion=1'

Related

Run inno script compiler in gitlab cicd

I enable CI/CD in gitlab.
I would like to, in the build job, compile a setup made with inno setup. This is yaml gitlab configuration related to build job:
build:
stage: build
script:
- echo building project...
- C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\msbuild /target:Build /property:config=Release /verbosity:q Project1.dproj /p:DCC_BuildAllUnits=true /p:"Platform=Win32"
- iscc "path/file.iss"
artifacts:
name: "test"
paths:
- Win32\Release\Project1.exe
But, when i execute the pipeline I got this error:
ISCC : Termine 'ISCC' non riconosciuto come nome di cmdlet, funzione, programma eseguibile o file script. Controllare
l'ortografia del nome o verificare che il percorso sia incluso e corretto, quindi riprovare.
I launch this pipeline in my windows machine and I already add environment variables in the system.
Anyone has idea why is wrong?
Thanks in advance
You probably need to specify the full path to your InnoSetup installation folder, or add the folder to the PATH in System Environment variables.

How to run Specflow test cases in pipeline of Gitlab for CI/CD implementaiton

I want to implement CI/CD so that whenever dev team commits any changes in their build then my whole automation suite runs before build and deployment.
I have yml file in GitLab and automated test case scripts in Visual Studio (Specflow framework in C#).
Please find below yml file:
demo_job_1:
stage: test
tags:
- win
script:
- echo "Test 1 started"
- '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\Extensions\TestPlatform\vstest.console.exe /ProjName.dll"'
- '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\MSTest /testcontainer:D:\Users\username\source\repos\Project\ProjName\bin\Debug\netcoreapp3.1\ProjName.dll"'
- "D:\Users\username\source\repos\Project\ProjName\ProjName.sln\Test\TestFeature1.csproj"'
But my job is passing without actually executing any of the test cases from the project
Folder structure in Visual studio:
I tried to do many changes in the path but none worked. Am I entering the wrong path? Can anyone please help me with this? If the yml file is completely wrong then can someone please guide me in the same? Thanks in advance!!! :)
P.S: I had validated yml before committing it and ymlvalidator showed it as the correct yml file.
demo_job_1:
stage: test
tags:
- tags
script:
- Root dir location path
- 'dotnet restore <path to the ProjName.sln>'
- 'dotnet msbuild <path to the ProjName.sln>'
- 'dotnet test <path to the ProjName.sln>'
Hope this helps others too!!!

Using variables as source and target folders, cause error in .gitlab-ci.yml file

I'm using gitlab and in the root of my repository, I have a Level4UI project, I want to copy the binary files into a temporary directory after build completed.
So, I defined the following .gitlab-ci.yml file in my GitLab repository:
variables:
EXE_RELEASE_FOLDER: '.\Level4UI\bin\Release2'
EXE_LOCAL_TEMP_FOLDER: 'c:\NewLevel4'
stages:
- build
build:
stage: build
script:
- nuget restore
- msbuild MySolution.sln /t:Build /p:Configuration=Release
- 'xcopy /y $env:EXE_RELEASE_FOLDER\*.* $env:EXE_LOCAL_TEMP_FOLDER\'
When the build completes, I get following error:
File not found - .
0 File(s) copied
ERROR: Job failed: exit status 4
Where is the problem?
You don't need an $env to use your variables in a script section, just use them like this:
- 'xcopy /y $EXE_RELEASE_FOLDER\*.* $EXE_LOCAL_TEMP_FOLDER\'

Cloud Variables not being set using Nerdbank.GitVersioning with Gitlab CI

I'm using the Nuget package Nerdbank.GitVersioning to version my C# .Net DLL project and it is all working for local builds (tried within VS2017).
However when I try with the Gitlab runner to obtain the version number for use during my Nuget packaging steps none of the environment variables have been set regardless of what I have in my version.json file and/or using the nbgv cloud tool
My version.json file looks like this and is in the root of the repo;
{
"$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "2.0",
"cloudBuild": {
"setVersionVariables": true,
"setAllVariables": true,
"buildNumber": {
"enabled": false,
"includeCommitId": {
"when": "nonPublicReleaseOnly",
"where": "buildMetadata"
}
}
}
}
My .gitlab-ci.yml file looks like this;
#Windows Configuration
variables:
GIT_SUBMODULE_STRATEGY: "normal"
URL: "https://localhost/repository/nuget-hosted"
before_script:
- echo "Restoring nuget packages"
- 'nuget restore MyProject.sln'
#- echo "Installing NB.GV - GitVersioning Tool"
- dotnet tool install --tool-path . nbgv
vs-15-2017-release-develop-build:
stage: deploy
script:
- echo "Building in Release mode"
- 'msbuild my-project.sln /p:Configuration=Release /p:PublicRelease=true'
- echo "Testing in Release mode"
- 'VSTest.Console.exe build/Release/MyProject.Test/MyProject.Test.dll'
- echo "deploying build to internal nuget"
- .\nbgv cloud
- set #output all env variables for debug
- nuget pack build/Release/MyProject/MyProject.nuspec -Version %BuildVersion% -Verbosity detailed
- nuget push MyProject.%VERSION%.nupkg -source %URL% -apikey [removed]
tags:
- vs-15-2017
I've tried various different combinations of setting the cloudBuild parameters but nothing ever outputs the variables to the environment.
A secondary issue (and may be related) is that setting buildNumber.enabled = true does not update the Gitlab build/job number too.
Thanks in advance for any help.
Cheers
Dave
Nerdbank.GitVersioning doesn't have an implementation for GitLab CI that can set the cloud build number. It can recognize when running in GitLab CI, but has no code in the SetCloudBuildNumber method. Care to share a PR if you know how to make this work?

GitLab CI: Unable to set JAVA_HOME

I am running git-lab server with Ubuntu 14 I am trying to compile a build on git-lab Ci but for some reasons I keep getting the same error over and over again:
ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-7-openjdk-amd64/jre Please set the JAVA_HOME variable in your environment to match the location of your Java installation.
No matter how I change the path of JAVA_HOME it is always the same results. I have 4 folders inside the JVM folder:
java-8-oracle
java-7-openjdk-amd64
java-1.7.0-openjdk-amd64
default-java
But again no matter which directory I set the path to it is always the same result.
Here is my .gitlab-ci.yml file:
before_script:
- export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre
- export ANDROID_HOME="/opt/android-sdk"
- chmod +x gradlew
dev:
script:
- ./gradlew assembleDebug
What could be the cause of this error?
Try to change your .gitlab-ci.yml to this:
before_script:
- export ANDROID_HOME="/opt/android-sdk"
- export JAVA_HOME="/usr/lib/jvm/java-1.7.0-openjdk-amd64"
- chmod +x gradlew
dev:
script:
- ./gradlew assembleDebug
You can try removing chmod +x gradlew from before_script and move it to the main script:
before_script:
- export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre
- export ANDROID_HOME="/opt/android-sdk"
dev:
script:
- chmod +x ./gradlew
- ./gradlew assembleDebug
Reference: https://about.gitlab.com/blog/2018/10/24/setting-up-gitlab-ci-for-android-projects/#comment-4440925341
I know this issue might have been fixed already. But here is how I fixed mine.
Use case:
After I updated Java on my 3 environmennts(Dev, Staging, and Prod), everithing worked just fine on Dev and Staging. But, for some reasons, the pipeline job in charge of deployment on production kept sending this error: "ERROR: JAVA_HOME is set to an invalid directory: C:/Program Files/Java/jdk1.8.0_171. Please set the JAVA_HOME variable in your environment to match the location of your Java installation."
My JAVA_HOME was set to the correct path.
Fix:
0. make sur you Java_Home is properly set up. Fir windows users, something like C:/your jdk root folder/ (do not add /bin folder).
1. Clear the runner caches in gitlab.
2. Restart the gitlab-runner service on your deployment server.
I hope that could help someone else.

Resources