FunctionApp works fine when deployed from Visual Studio using the downloaded publish profile from Azure. But when I try to deploy from Gitlab using ci/cd pipeline, the FunctionApp is not displayed in Azure.
I downloaded the app content from Azure portal for both deployments and compared the folders. I could find the exe in the app content that was published from Visual Studio but code deployed by Gitlab pipeline compiled to dll.
For some reason OutputType Exe setting in the project file is being ignored by the Gitlab pipeline.
After migrating FunctionApps to isolated model, I updated the git.yml file to use mcr.microsoft.com/dotnet/sdk:8.0 image and these are the commands to build/publish
- dotnet build $SLN_PATH -c Release -v d
- dotnet publish $SLN_PATH -o ./out -c Release
The FunctionApp was working fine with in-process model and sdk:6.0 image for both deployments (from Visual Studio using publish profile & Gitlab pipeline). Not sure if anything chaged in sdk:8.0 image.
How can I make it publish an exe instead of dll?
Visual Studio compiling to exe but gitlab pipeline is producing a dll
gitlab yml file
stages:
- build
- deploy
variables:
GIT_PROJECT_CLONE: 'https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/xyz/functionApp-net8.git --branch main'
DOTNET_PUBLISH_ARGS: "${DOTNET_BUILD_ARGS} /p:Configuration=Release /p:DeployOnBuild=true /p:PublishProfile=${PROFILE_NAME}"
BUILD_ARTIFACTS: "./src/**/bin/**"
NUGET_PACKAGES: "${CI_PROJECT_DIR}/.nugetcache"
DOTNET_BUILD_ARGS: "-c Release -v d"
AZURE_CLIENT_ID: "xyz"
AZURE_RESOURCE_TYPE: "azure_functions"
AZURE_CLI_PARAMS: "--verbose"
build:
image: mcr.microsoft.com/dotnet/sdk:8.0
stage: build
script:
- 'apt-get update && apt-get install -y zip'
- |
if [ -z "${GIT_PROJECT_CLONE}" ] ; then
echo "[INFO] GIT_PROJECT_CLONE not set, skip clone"
else
echo "[INFO] GIT_PROJECT_CLONE is set , do clone ${GIT_PROJECT_CLONE}"
cd ..
git clone $GIT_PROJECT_CLONE
ls -lart
cd $CI_PROJECT_DIR
fi
- |
if [ -z "${SLN_PATH}" ] ; then
echo "[INFO] SLN_PATH not set, searching for .sln"
SLN_PATH=`find . -type f -regex ".*.sln"`
fi
echo "[INFO] SLN_PATH set to ${SLN_PATH}."
dotnet build $SLN_PATH $DOTNET_BUILD_ARGS
echo "[INFO] DOTNET_PUBLISH_ARGS set to ${DOTNET_PUBLISH_ARGS}."
echo "[INFO] actual dotnet publish ${SLN_PATH} ${DOTNET_PUBLISH_ARGS}"
dotnet publish $SLN_PATH -o ./out -c Release
ls -lart
cd $OUT_FOLDER
ls -lart
zip -r ../out.zip *
cd ..
ls -lart
cd $CI_PROJECT_DIR
artifacts:
paths:
- $OUT_FOLDER
- $OUT_FOLDER.zip
expire_in: 1 week
cache:
key: "$CI_JOB_STAGE-$CI_COMMIT_REF_SLUG"
paths:
- .nugetcache
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
when: never
- if: $CI_COMMIT_TAG != null
when: never
- when: on_success
.deploy:
stage: deploy
id_tokens:
CI_JOB_JWT:
aud: "vault"
secrets:
AZURE_PASSWORD:
vault: AZURE_PASSWORD@xyz
variables:
AZURE_RESOURCE_GROUP: "xyz"
AZURE_SUBSCRIPTION: "xyz"
AZURE_TENANTID: "xyz"
AZURE_USERNAME: "xyz"
AZURE_APP_NAME: "$AZURE_APP_NAME"
extends: .azure_deploy
environment:
name: test/azure/${AZURE_RESOURCE_GROUP}/functionapp/${AZURE_APP_NAME}
url: https://${AZURE_APP_NAME}.scm.azurewebsites.net
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
when: never
- if: $CI_COMMIT_TAG != null
when: never
- when: on_success
2
Below given .yml
file worked for me.
zip the content of publish folder
stages:
- Build
- Deploy
variables:
function_name: "csharpfunc6sep"
Client_id: "xxxxxxxxxxxxxx"
Client_secret: "xxxxxxxxxxxxxxxx"
tenant_id: "xxxxxxxxxxxxxx"
Build:
stage: Build
image: mcr.microsoft.com/dotnet/sdk:8.0
script:
- apt-get update && apt-get install -y zip
- dotnet publish --configuration Release --output ./output
- cd output
- zip -r ../output.zip ./*
artifacts:
paths:
- ./output.zip
expire_in: 1 day
Deploy:
stage: Deploy
script:
- curl -sL https://aka.ms/InstallAzureCLIDeb | bash
- az login --service-principal -u $Client_id -p $Client_secret --tenant $tenant_id
- az functionapp deployment source config-zip --resource-group Vivek-RG --name $function_name --src ./output.zip
dependencies:
- Build
rules:
- when: on_success
NOTE :- Node images with core-tools tag can also be used in
Deploy
stage likemcr.microsoft.com/azure-functions/node:4-node20-core-tools
for runningaz
andfunc
command as Azure CLI and Azure Function core tools are inbuilt in these images.
Currently
func
command support onlynet6.0
for dotnet-isolated during deployment usingfunc
.
OUTPUT
: