From 5f1b87e317e74cadd0eb86a624a3959bd80e997b Mon Sep 17 00:00:00 2001 From: "Patrick O. Baidoo-Antwi" Date: Tue, 24 May 2022 16:31:20 +0200 Subject: [PATCH 01/11] wip: add build pipeline for devon4net --- .../azure-devops/setup-build-pipeline.asciidoc | 5 +++++ .../azure-devops/pipeline_generator.sh | 3 ++- .../templates/build/build-pipeline.cfg | 18 ++++++++++++++++++ .../build/build-pipeline.yml.template | 2 +- .../templates/build/dotnet-build.sh | 3 +++ 5 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 scripts/pipelines/azure-devops/templates/build/dotnet-build.sh diff --git a/documentation/azure-devops/setup-build-pipeline.asciidoc b/documentation/azure-devops/setup-build-pipeline.asciidoc index c0e5dea91..47be3fb8b 100644 --- a/documentation/azure-devops/setup-build-pipeline.asciidoc +++ b/documentation/azure-devops/setup-build-pipeline.asciidoc @@ -45,4 +45,9 @@ NOTE: The config file for the build pipeline is located at `/scripts/pipelines/a ./pipeline_generator.sh -c ./templates/build/build-pipeline.cfg -n quarkus-project-build -l quarkus -d C:/Users/$USERNAME/Desktop/quarkus-project -b develop -w ``` +==== .Net project +``` +./pipeline_generator.sh -c ./templates/build/build-pipeline.cfg -n dotnet-project-build -l dotnet -d C:/Users/$USERNAME/Desktop/dotnet-project -b develop -w +``` + CAUTION: Remember to write the path to the local repository with '/' and not '\' on Windows. diff --git a/scripts/pipelines/azure-devops/pipeline_generator.sh b/scripts/pipelines/azure-devops/pipeline_generator.sh index 3edeb985f..31e66d7ea 100644 --- a/scripts/pipelines/azure-devops/pipeline_generator.sh +++ b/scripts/pipelines/azure-devops/pipeline_generator.sh @@ -1,6 +1,6 @@ #!/bin/bash set -e -FLAGS=$(getopt -a --options c:n:d:a:b:l:i:u:p:hw --long "config-file:,pipeline-name:,local-directory:,artifact-path:,target-branch:,language:,build-pipeline-name:,sonar-url:,sonar-token:,image-name:,registry-user:,registry-password:,resource-group:,storage-account:,storage-container:,cluster-name:,s3-bucket:,s3-key-path:,quality-pipeline-name:,dockerfile:,test-pipeline-name:,aws-access-key:,aws-secret-access-key:,aws-region:,help" -- "$@") +FLAGS=$(getopt -a --options c:n:d:a:b:l:t:i:u:p:hw --long "config-file:,pipeline-name:,local-directory:,artifact-path:,target-branch:,language:,target-directory:,build-pipeline-name:,sonar-url:,sonar-token:,image-name:,registry-user:,registry-password:,resource-group:,storage-account:,storage-container:,cluster-name:,s3-bucket:,s3-key-path:,quality-pipeline-name:,dockerfile:,test-pipeline-name:,aws-access-key:,aws-secret-access-key:,aws-region:,help" -- "$@") eval set -- "$FLAGS" while true; do @@ -11,6 +11,7 @@ while true; do -a | --artifact-path) artifactPath=$2; shift 2;; -b | --target-branch) targetBranch=$2; shift 2;; -l | --language) language=$2; shift 2;; + -t | --target-directory) targetDirectory=$2; shift 2;; --build-pipeline-name) export buildPipelineName=$2; shift 2;; --sonar-url) sonarUrl=$2; shift 2;; --sonar-token) sonarToken=$2; shift 2;; diff --git a/scripts/pipelines/azure-devops/templates/build/build-pipeline.cfg b/scripts/pipelines/azure-devops/templates/build/build-pipeline.cfg index abcc07fab..2ffc4ad7a 100644 --- a/scripts/pipelines/azure-devops/templates/build/build-pipeline.cfg +++ b/scripts/pipelines/azure-devops/templates/build/build-pipeline.cfg @@ -17,4 +17,22 @@ scriptFilePath=".pipelines/scripts" function copyScript { # Copy the script. cp "${hangarPath}/${templatesPath}/${language}-${scriptFile}" "${localDirectory}/${scriptFilePath}/${scriptFile}" +} + +# Function that adds the variables to be used in the pipeline. +function addPipelineVariables { + # if the user did not specify a custom target-directory + # we default to the language specific defaults e.g. target for java, ./ for node + + if test -z $targetDirectory + then + case $language in + node) targetDirectory="./" ;; + quarkus*) targetDirectory="./target/" ;; + dotnet) targetDirectory="./obj/" ;; + *) targetDirectory="./" + esac + fi + + az pipelines variable create --name "targetPath" --pipeline-name "${pipelineName}" --value "${targetDirectory}" } \ No newline at end of file diff --git a/scripts/pipelines/azure-devops/templates/build/build-pipeline.yml.template b/scripts/pipelines/azure-devops/templates/build/build-pipeline.yml.template index a521928c1..9e4f33009 100644 --- a/scripts/pipelines/azure-devops/templates/build/build-pipeline.yml.template +++ b/scripts/pipelines/azure-devops/templates/build/build-pipeline.yml.template @@ -17,4 +17,4 @@ steps: - publish: $(Build.Repository.LocalPath)/$(targetPath) displayName: "Publish Artifact" - artifact: target \ No newline at end of file + artifact: $(targetPath) \ No newline at end of file diff --git a/scripts/pipelines/azure-devops/templates/build/dotnet-build.sh b/scripts/pipelines/azure-devops/templates/build/dotnet-build.sh new file mode 100644 index 000000000..686df7ae5 --- /dev/null +++ b/scripts/pipelines/azure-devops/templates/build/dotnet-build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +dotnet build -o "$targetDirectory" \ No newline at end of file From 5fecc8b7d840425061042dd1aa90cf264ae79b0a Mon Sep 17 00:00:00 2001 From: "Patrick O. Baidoo-Antwi" Date: Wed, 1 Jun 2022 10:44:35 +0200 Subject: [PATCH 02/11] wip --- scripts/pipelines/azure-devops/pipeline_generator.sh | 1 + scripts/pipelines/azure-devops/templates/build/dotnet-build.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/pipelines/azure-devops/pipeline_generator.sh b/scripts/pipelines/azure-devops/pipeline_generator.sh index 31e66d7ea..849dadb27 100644 --- a/scripts/pipelines/azure-devops/pipeline_generator.sh +++ b/scripts/pipelines/azure-devops/pipeline_generator.sh @@ -58,6 +58,7 @@ function help { echo "" echo "Build pipeline flags:" echo " -l, --language [Required] Language or framework of the project." + echo " -t, --target-directory [Required, if language is dotnet] The output directory to place built artifacts in." echo "" echo "Test pipeline flags:" echo " -l, --language [Required] Language or framework of the project." diff --git a/scripts/pipelines/azure-devops/templates/build/dotnet-build.sh b/scripts/pipelines/azure-devops/templates/build/dotnet-build.sh index 686df7ae5..45f8dff41 100644 --- a/scripts/pipelines/azure-devops/templates/build/dotnet-build.sh +++ b/scripts/pipelines/azure-devops/templates/build/dotnet-build.sh @@ -1,3 +1,3 @@ #!/bin/bash -dotnet build -o "$targetDirectory" \ No newline at end of file +dotnet build -c Release -o "$targetDirectory" \ No newline at end of file From 0b32f4214d76b76382e9cc6b00cd066016b4b663 Mon Sep 17 00:00:00 2001 From: "Patrick O. Baidoo-Antwi" Date: Wed, 1 Jun 2022 12:13:14 +0200 Subject: [PATCH 03/11] wip fix build script --- .../azure-devops/templates/build/dotnet-build.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/pipelines/azure-devops/templates/build/dotnet-build.sh b/scripts/pipelines/azure-devops/templates/build/dotnet-build.sh index 45f8dff41..2fef2ea10 100644 --- a/scripts/pipelines/azure-devops/templates/build/dotnet-build.sh +++ b/scripts/pipelines/azure-devops/templates/build/dotnet-build.sh @@ -1,3 +1,10 @@ #!/bin/bash -dotnet build -c Release -o "$targetDirectory" \ No newline at end of file +echo "debug:building .net" +# dotnet build "Templates/WebAPI/Devon4Net.Application.WebAPI/Devon4Net.Application.WebAPI.csproj" -c Release +dotnet build -c Release + +echo "debug:publishing ... ${targetDirectory}" +# dotnet publish "Templates/WebAPI/Devon4Net.Application.WebAPI/Devon4Net.Application.WebAPI.csproj" -c Release -o "${targetDirectory}" +dotnet publish -c Release -o "${targetDirectory}" + From 337a4e4720696c7a0a03c036d567a53a19eb6106 Mon Sep 17 00:00:00 2001 From: "Patrick O. Baidoo-Antwi" Date: Tue, 21 Jun 2022 17:58:13 +0200 Subject: [PATCH 04/11] cleanup dotnet build script --- .../azure-devops/templates/build/dotnet-build.sh | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/scripts/pipelines/azure-devops/templates/build/dotnet-build.sh b/scripts/pipelines/azure-devops/templates/build/dotnet-build.sh index 2fef2ea10..99d0ffefb 100644 --- a/scripts/pipelines/azure-devops/templates/build/dotnet-build.sh +++ b/scripts/pipelines/azure-devops/templates/build/dotnet-build.sh @@ -1,10 +1,2 @@ -#!/bin/bash - -echo "debug:building .net" -# dotnet build "Templates/WebAPI/Devon4Net.Application.WebAPI/Devon4Net.Application.WebAPI.csproj" -c Release -dotnet build -c Release - -echo "debug:publishing ... ${targetDirectory}" -# dotnet publish "Templates/WebAPI/Devon4Net.Application.WebAPI/Devon4Net.Application.WebAPI.csproj" -c Release -o "${targetDirectory}" -dotnet publish -c Release -o "${targetDirectory}" - +#!/bin/bash +dotnet build -c Release From d15b77955703b38e7e457bd2de6185a3daebd3a0 Mon Sep 17 00:00:00 2001 From: "Patrick O. Baidoo-Antwi" Date: Fri, 24 Jun 2022 14:38:32 +0200 Subject: [PATCH 05/11] temporal fix: use empty string as targetPath for dotnet --- .../pipelines/azure-devops/templates/build/build-pipeline.cfg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/pipelines/azure-devops/templates/build/build-pipeline.cfg b/scripts/pipelines/azure-devops/templates/build/build-pipeline.cfg index 531044bb0..89ebabc29 100644 --- a/scripts/pipelines/azure-devops/templates/build/build-pipeline.cfg +++ b/scripts/pipelines/azure-devops/templates/build/build-pipeline.cfg @@ -25,7 +25,8 @@ function addPipelineVariables { case $language in node | angular) targetDirectory="." ;; quarkus*) targetDirectory="./target/" ;; - dotnet) targetDirectory="./obj/" ;; + # error occurs when targetDirectory="./obj/" + dotnet) targetDirectory="" ;; *) echo -e "${red}Error: Specified language '${language}' is not supported." >&2; exit 1 esac fi From 83e7a082f6e1684cfd1626e1ea1f41494ee7ce6e Mon Sep 17 00:00:00 2001 From: "Patrick O. Baidoo-Antwi" Date: Fri, 24 Jun 2022 14:42:24 +0200 Subject: [PATCH 06/11] remove caution message about line endings Co-authored-by: shiftwolf <54272779+shiftwolf@users.noreply.github.com> --- documentation/azure-devops/setup-build-pipeline.asciidoc | 2 -- 1 file changed, 2 deletions(-) diff --git a/documentation/azure-devops/setup-build-pipeline.asciidoc b/documentation/azure-devops/setup-build-pipeline.asciidoc index 835b82fa2..456913f5b 100644 --- a/documentation/azure-devops/setup-build-pipeline.asciidoc +++ b/documentation/azure-devops/setup-build-pipeline.asciidoc @@ -66,5 +66,3 @@ NOTE: The config file for the build pipeline is located at `/scripts/pipelines/a ``` ./pipeline_generator.sh -c ./templates/build/build-pipeline.cfg -n dotnet-project-build -l dotnet -d C:/Users/$USERNAME/Desktop/dotnet-project -b develop -w ``` - -CAUTION: Remember to write the path to the local repository with '/' and not '\' on Windows. From a036412e99ccad088860351269aaf9249876d3a4 Mon Sep 17 00:00:00 2001 From: "Patrick O. Baidoo-Antwi" Date: Thu, 30 Jun 2022 12:12:15 +0200 Subject: [PATCH 07/11] rename pipeline variable - targetPath to buildTargetPath --- .../pipelines/azure-devops/templates/build/build-pipeline.cfg | 2 +- .../azure-devops/templates/build/build-pipeline.yml.template | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/pipelines/azure-devops/templates/build/build-pipeline.cfg b/scripts/pipelines/azure-devops/templates/build/build-pipeline.cfg index 89ebabc29..68597e30d 100644 --- a/scripts/pipelines/azure-devops/templates/build/build-pipeline.cfg +++ b/scripts/pipelines/azure-devops/templates/build/build-pipeline.cfg @@ -31,5 +31,5 @@ function addPipelineVariables { esac fi - az pipelines variable create --name "targetPath" --pipeline-name "${pipelineName}" --value "${targetDirectory}" + az pipelines variable create --name "buildTargetPath" --pipeline-name "${pipelineName}" --value "${targetDirectory}" } \ No newline at end of file diff --git a/scripts/pipelines/azure-devops/templates/build/build-pipeline.yml.template b/scripts/pipelines/azure-devops/templates/build/build-pipeline.yml.template index e1c7991f2..5fc35228f 100644 --- a/scripts/pipelines/azure-devops/templates/build/build-pipeline.yml.template +++ b/scripts/pipelines/azure-devops/templates/build/build-pipeline.yml.template @@ -16,7 +16,7 @@ steps: displayName: "Copying build artifact to the ArtifactStagingDirectory" inputs: targetType: inline - script: 'cp -a $(Build.Repository.LocalPath)/$(targetPath) $(Build.ArtifactStagingDirectory)' + script: 'cp -a $(Build.Repository.LocalPath)/$(buildTargetPath) $(Build.ArtifactStagingDirectory)' - publish: $(Build.ArtifactStagingDirectory) displayName: "Publish Artifact" From d38a8e28a149b66841eb68e094876bd9a0263443 Mon Sep 17 00:00:00 2001 From: "Patrick O. Baidoo-Antwi" Date: Thu, 30 Jun 2022 14:27:46 +0200 Subject: [PATCH 08/11] set build output directory --- .../azure-devops/templates/build/build-pipeline.cfg | 5 ++--- .../pipelines/azure-devops/templates/build/dotnet-build.sh | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/scripts/pipelines/azure-devops/templates/build/build-pipeline.cfg b/scripts/pipelines/azure-devops/templates/build/build-pipeline.cfg index 68597e30d..be359c055 100644 --- a/scripts/pipelines/azure-devops/templates/build/build-pipeline.cfg +++ b/scripts/pipelines/azure-devops/templates/build/build-pipeline.cfg @@ -24,9 +24,8 @@ function addPipelineVariables { then case $language in node | angular) targetDirectory="." ;; - quarkus*) targetDirectory="./target/" ;; - # error occurs when targetDirectory="./obj/" - dotnet) targetDirectory="" ;; + quarkus*) targetDirectory="./target/" ;; + dotnet) targetDirectory="./build/" ;; *) echo -e "${red}Error: Specified language '${language}' is not supported." >&2; exit 1 esac fi diff --git a/scripts/pipelines/azure-devops/templates/build/dotnet-build.sh b/scripts/pipelines/azure-devops/templates/build/dotnet-build.sh index 99d0ffefb..448e21bfa 100644 --- a/scripts/pipelines/azure-devops/templates/build/dotnet-build.sh +++ b/scripts/pipelines/azure-devops/templates/build/dotnet-build.sh @@ -1,2 +1,2 @@ #!/bin/bash -dotnet build -c Release +dotnet build -c Release -o $BUILDTARGETPATH From 79e9f048549014a974c8c8ff000d2aa599bb5e33 Mon Sep 17 00:00:00 2001 From: "Patrick O. Baidoo-Antwi" Date: Thu, 30 Jun 2022 15:09:31 +0200 Subject: [PATCH 09/11] double quote variable to prevent globbing and word splitting --- scripts/pipelines/azure-devops/templates/build/dotnet-build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pipelines/azure-devops/templates/build/dotnet-build.sh b/scripts/pipelines/azure-devops/templates/build/dotnet-build.sh index 448e21bfa..59e16f449 100644 --- a/scripts/pipelines/azure-devops/templates/build/dotnet-build.sh +++ b/scripts/pipelines/azure-devops/templates/build/dotnet-build.sh @@ -1,2 +1,2 @@ #!/bin/bash -dotnet build -c Release -o $BUILDTARGETPATH +dotnet build -c Release -o "$BUILDTARGETPATH" From 844f46287d043ce335d6dddd32c310d1f8db0fc4 Mon Sep 17 00:00:00 2001 From: patricpoba Date: Mon, 18 Jul 2022 16:02:40 +0000 Subject: [PATCH 10/11] Automatic generation of documentation --- documentation/azure-devops/setup-build-pipeline.asciidoc | 5 ----- 1 file changed, 5 deletions(-) diff --git a/documentation/azure-devops/setup-build-pipeline.asciidoc b/documentation/azure-devops/setup-build-pipeline.asciidoc index 347552183..0b467d05f 100644 --- a/documentation/azure-devops/setup-build-pipeline.asciidoc +++ b/documentation/azure-devops/setup-build-pipeline.asciidoc @@ -69,8 +69,3 @@ NOTE: The config file for the build {pipeline_type} is located at `/scripts/pipe ``` ./pipeline_generator.sh -c ./templates/build/build-pipeline.cfg -n angular-project-build -l angular -d C:/Users/$USERNAME/Desktop/angular-project -b develop -w ``` - -==== .Net project -``` -./pipeline_generator.sh -c ./templates/build/build-pipeline.cfg -n dotnet-project-build -l dotnet -d C:/Users/$USERNAME/Desktop/dotnet-project -b develop -w -``` From de50ed08dbaae40c0be9bdff0f97e8b76359933e Mon Sep 17 00:00:00 2001 From: Patrick Poba Date: Mon, 18 Jul 2022 16:10:28 +0000 Subject: [PATCH 11/11] re-add target directory for dotnet build (after refactoring) --- scripts/pipelines/common/pipeline_generator.lib | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/pipelines/common/pipeline_generator.lib b/scripts/pipelines/common/pipeline_generator.lib index 1c6f092dc..e737f837c 100644 --- a/scripts/pipelines/common/pipeline_generator.lib +++ b/scripts/pipelines/common/pipeline_generator.lib @@ -217,6 +217,7 @@ function setTargetDirectory { case $language in node | angular) targetDirectory="./" ;; quarkus*) targetDirectory="./target/" ;; + dotnet) targetDirectory="./build/" ;; *) echo -e "${red}Error: Specified language '${language}' is not supported." >&2; exit 1 esac }