How to publish a docker image when you use spring-boot:build-image - spring-boot

I am using Github Actions to automate the process to push a docker image generated with the help of the maven plugin from Spring boot (mvn spring-boot:build-image), but I receive a maven error:
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution
default-cli of goal
org.springframework.boot:spring-boot-maven-plugin:3.0.0:build-image
failed: Error response received when pushing image: denied: requested
access to the resource is denied
Using the following configuration:
- name: Build image & push
run: |
cd myFolder
mvn -X spring-boot:build-image \
--batch-mode --no-transfer-progress \
-Dspring-boot.build-image.publish=true \
-Dspring-boot.build-image.imageName="MY_USER/demo-ms:0.1.0" \
-DCI_REGISTRY=https://index.docker.io/v1 \
-DCI_REGISTRY_USER=${{ secrets.DOCKERHUB_USERNAME }} \
-DCI_REGISTRY_PASSWORD=${{ secrets.DOCKERHUB_TOKEN }}
https://docs.spring.io/spring-boot/docs/current/maven-plugin/reference/htmlsingle/#build-image.examples.docker.auth
What I am missing?
Many thanks in advance
Juan Antonio

In github actions, it is possible to run a Script, so I found an alternative:
At github action level:
- name: Build image & push
run: |
cd myFolder
./build-spring-boot.sh ${{ secrets.DOCKERHUB_USERNAME }} ${{ secrets.DOCKERHUB_PASSWORD }}
At script level:
docker login "https://index.docker.io/v1/" -u="$1" -p="$2"
mvn spring-boot:build-image \
--batch-mode --no-transfer-progress
IMAGE_NAME=$(mvn help:evaluate -Dexpression=docker.image.name -q -DforceStdout)
echo $IMAGE_NAME
docker push $IMAGE_NAME
In this way, you can publish your image.

Related

sonarqube scanner on circleci

I am using Sonarqube and CircleCI for code quality scan.
However, I don't know how if it is possible to start up a Sonarqube Server on CircleCI and use it to run the scanner.
This is my current config.yaml
version: 2.1
executors:
scanner:
docker:
- image: openjdk:11
commands:
check-code-quality:
description: Check Code Quality
parameters:
sonar_server_url:
type: string
description: "URL of your SonarQube server. e.g.: http://my.sonarqube,server:9000"
default: "$SONAR_SERVER"
sonar_login:
description: "Authentication key (sonar.login paramter) to access SonarQube and perform analysis"
type: string
default: "$SONAR_TOKEN"
sonar_sources:
description: "Where the files are located?"
type: string
default: "$SONAR_SOURCES"
steps:
- run:
name: Install Sonarqube scanner
command: |
wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.2.0.1873.zip
unzip sonar-scanner-cli-4.2.0.1873.zip
- run:
name: Run Sonarscanner
command: |
export SONAR_SCANNER_OPTS="-Xmx2048m"
eval ./sonar-scanner-4.2.0.1873/bin/sonar-scanner \
-Dsonar.projectKey=projectKey
-Dsonar.host.url=<< parameters.sonar_server_url >> \
-Dsonar.sources=<< parameters.sonar_sources >> \
-Dsonar.login=<< parameters.sonar_login >>
jobs:
check-code-job:
executor: scanner
steps:
- check-code-quality
workflows:
check-code-quality-flow:
jobs:
- check-code-job:
context: lineclass
There is an error log when the job being executed:
...
Caused by: java.lang.IllegalStateException: Fail to get bootstrap index from server
at org.sonarsource.scanner.api.internal.BootstrapIndexDownloader.getIndex(BootstrapIndexDownloader.java:42)
at org.sonarsource.scanner.api.internal.JarDownloader.getScannerEngineFiles(JarDownloader.java:58)
at org.sonarsource.scanner.api.internal.JarDownloader.download(JarDownloader.java:53)
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:76)
... 7 more
Caused by: java.net.ConnectException: Failed to connect to localhost/127.0.0.1:9000
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.R...
This indicates that the Sonarqube Server is missing.
If you have experience running sonar-scanner on CircleCI please help.
Thank you.
After I change the image to sonarqube:8.9-community and fix the missing \ in the sonar-scanner command (at the end of -Dsonar.projectKey), it works.

Build docker image with azure pipelines still 401 (Unauthorized)

I'm trying to build a linux docker image via azure pipelines.
Main problem is with restore from private feed.
I read many article how to do that but still getting same error
"error : Response status code does not indicate success: 401 (Unauthorized)."
So how its looks my files
Dockerfile:
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-alpine AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine AS build
WORKDIR /src
COPY MyAppService/MyAppService.csproj MyAppService/
COPY NuGet.Config .
ARG NUGET_PAT
ARG AZURE_FEED
ENV NUGET_CREDENTIALPROVIDER_SESSIONTOKENCACHE_ENABLED true
ENV VSS_NUGET_EXTERNAL_FEED_ENDPOINTS "{\"endpointCredentials\": [{\"endpoint\":\"${AZURE_FEED}\", \"username\":\"docker\", \"password\":\"${NUGET_PAT}\"}]}"
RUN wget -O - https://aka.ms/install-artifacts-credprovider.sh
# check env are ok
RUN printenv
RUN dotnet restore --configfile NuGet.Config "MyAppService/MyAppService.csproj"
COPY MyAppService/. MyAppService/
RUN dotnet build "MyAppService/MyAppService.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "MyAppService/MyAppService.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MyAppService.dll"]
NuGet.Config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="mytestorganization" value="https://pkgs.dev.azure.com/mytestorganization/_packaging/mytestorganization/nuget/v3/index.json" />
</packageSources>
</configuration>
And log file from azure pipeline when trying build a image:
2021-05-20T11:36:22.7867465Z ##[section]Starting: build
2021-05-20T11:36:22.7875209Z ==============================================================================
2021-05-20T11:36:22.7875497Z Task : Docker
2021-05-20T11:36:22.7875990Z Description : Build or push Docker images, login or logout, start or stop containers, or run a Docker command
2021-05-20T11:36:22.7876270Z Version : 2.185.0
2021-05-20T11:36:22.7876466Z Author : Microsoft Corporation
2021-05-20T11:36:22.7876713Z Help : https://aka.ms/azpipes-docker-tsg
2021-05-20T11:36:22.7876983Z ==============================================================================
2021-05-20T11:36:27.0474614Z [command]/usr/bin/docker build -f /home/vsts/work/1/s/Dockerfile --label com.azure.dev.image.system.teamfoundationcollectionuri=https://dev.azure.com/mytestorganization/ --label com.azure.dev.image.system.teamproject=TestProject --label com.azure.dev.image.build.repository.name=MyAppService --label com.azure.dev.image.build.sourceversion=63bc9999e1005c9aec016231dcc0f15cf9ec83da --label com.azure.dev.image.build.repository.uri=https://mytestorganization#dev.azure.com/mytestorganization/TestProject/_git/MyAppService --label com.azure.dev.image.build.sourcebranchname=testbranch --label com.azure.dev.image.build.definitionname=TestProject-CI --label com.azure.dev.image.build.buildnumber=144 --label com.azure.dev.image.build.builduri=vstfs:///Build/Build/144 --build-arg AZURE_FEED=http://pkgs.dev.azure.com/mytestorganization/_packaging/mytestorganization/nuget/v3/index.json --build-arg NUGET_PAT=wz2ilhvt2urpzqlqlldd2f2hl6do77jkmreydrpmskwco3fc7sva /home/vsts/work/1/s
2021-05-20T11:36:30.9509673Z Sending build context to Docker daemon 203.3kB
2021-05-20T11:36:30.9510485Z
2021-05-20T11:36:31.0442686Z Step 1/32 : FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-alpine AS base
2021-05-20T11:36:31.2889870Z 3.1-alpine: Pulling from dotnet/core/aspnet
2021-05-20T11:36:31.2907305Z 540db60ca938: Already exists
2021-05-20T11:36:31.3239989Z 9c2872b91813: Pulling fs layer
2021-05-20T11:36:31.3240441Z 8628df474c5d: Pulling fs layer
2021-05-20T11:36:31.3240760Z b54f4c6d2c91: Pulling fs layer
2021-05-20T11:36:31.3981063Z 9c2872b91813: Verifying Checksum
2021-05-20T11:36:31.3981449Z 9c2872b91813: Download complete
2021-05-20T11:36:31.4335354Z b54f4c6d2c91: Verifying Checksum
2021-05-20T11:36:31.4339309Z b54f4c6d2c91: Download complete
2021-05-20T11:36:31.6869948Z 8628df474c5d: Verifying Checksum
2021-05-20T11:36:31.6870377Z 8628df474c5d: Download complete
2021-05-20T11:36:32.0023325Z 9c2872b91813: Pull complete
2021-05-20T11:36:33.1851800Z 8628df474c5d: Pull complete
2021-05-20T11:36:33.5201247Z b54f4c6d2c91: Pull complete
2021-05-20T11:36:33.5262719Z Digest: sha256:97c4986a2f9c8d2bc40443eb0baac59f35c43c267fc59ecc626b449701152df9
2021-05-20T11:36:33.5294596Z Status: Downloaded newer image for mcr.microsoft.com/dotnet/core/aspnet:3.1-alpine
2021-05-20T11:36:33.5314476Z ---> f039e2539446
2021-05-20T11:36:33.5314887Z Step 2/32 : WORKDIR /app
2021-05-20T11:36:33.5511196Z ---> Running in 935279916ded
2021-05-20T11:36:34.0084321Z Removing intermediate container 935279916ded
2021-05-20T11:36:34.0085263Z ---> acbf5abca7a7
2021-05-20T11:36:34.0085629Z Step 3/32 : EXPOSE 80
2021-05-20T11:36:34.0265101Z ---> Running in f7fa1a4dd856
2021-05-20T11:36:35.0147354Z Removing intermediate container f7fa1a4dd856
2021-05-20T11:36:35.0148907Z ---> ac616daad00f
2021-05-20T11:36:35.0152411Z Step 4/32 : EXPOSE 443
2021-05-20T11:36:35.0322549Z ---> Running in b3850b437c79
2021-05-20T11:36:36.0098236Z Removing intermediate container b3850b437c79
2021-05-20T11:36:36.0099219Z ---> cb4e679d3e31
2021-05-20T11:36:36.0099779Z Step 5/32 : FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine AS build
2021-05-20T11:36:36.5177448Z 3.1-alpine: Pulling from dotnet/core/sdk
2021-05-20T11:36:36.5178298Z 540db60ca938: Already exists
2021-05-20T11:36:36.5178735Z 9c2872b91813: Already exists
2021-05-20T11:36:36.5179120Z 8628df474c5d: Already exists
2021-05-20T11:36:36.5179575Z b54f4c6d2c91: Already exists
2021-05-20T11:36:36.5180041Z c1b534528ba7: Pulling fs layer
2021-05-20T11:36:36.5180819Z db0b8f999807: Pulling fs layer
2021-05-20T11:36:36.5181265Z 668300e8efd0: Pulling fs layer
2021-05-20T11:36:36.5181785Z 668300e8efd0: Verifying Checksum
2021-05-20T11:36:36.5182381Z 668300e8efd0: Download complete
2021-05-20T11:36:36.5182681Z c1b534528ba7: Verifying Checksum
2021-05-20T11:36:36.5182991Z c1b534528ba7: Download complete
2021-05-20T11:36:36.9095207Z db0b8f999807: Verifying Checksum
2021-05-20T11:36:36.9095902Z db0b8f999807: Download complete
2021-05-20T11:36:37.5777094Z c1b534528ba7: Pull complete
2021-05-20T11:36:41.4075714Z db0b8f999807: Pull complete
2021-05-20T11:36:42.0343103Z 668300e8efd0: Pull complete
2021-05-20T11:36:42.0398152Z Digest: sha256:468b7f80a5ddad15081eddf072ea67d2d003e82c7937392bf927692b134633f5
2021-05-20T11:36:42.0430106Z Status: Downloaded newer image for mcr.microsoft.com/dotnet/core/sdk:3.1-alpine
2021-05-20T11:36:42.0445206Z ---> a08ae6c8a2aa
2021-05-20T11:36:42.0445502Z Step 6/32 : WORKDIR /src
2021-05-20T11:36:42.0748860Z ---> Running in 6dae098fc8ed
2021-05-20T11:36:43.0138598Z Removing intermediate container 6dae098fc8ed
2021-05-20T11:36:43.0139677Z ---> e151bdc4004f
2021-05-20T11:36:43.0140964Z Step 7/32 : COPY MyAppService/MyAppService.csproj MyAppService/
2021-05-20T11:36:44.0159585Z ---> 30c607bb8a6e
2021-05-20T11:36:44.0159936Z Step 8/32 : COPY NuGet.Config .
2021-05-20T11:36:45.0146826Z ---> 21b4b5d1f04c
2021-05-20T11:36:45.0147184Z Step 9/32 : ARG NUGET_PAT
2021-05-20T11:36:45.0460635Z ---> Running in 88d83e60cf3a
2021-05-20T11:36:46.0172444Z Removing intermediate container 88d83e60cf3a
2021-05-20T11:36:46.0173490Z ---> 58d9dde29d1d
2021-05-20T11:36:46.0173821Z Step 10/32 : ARG AZURE_FEED
2021-05-20T11:36:46.0360209Z ---> Running in f10912b5009e
2021-05-20T11:36:47.0134976Z Removing intermediate container f10912b5009e
2021-05-20T11:36:47.0135971Z ---> e792f313ec6c
2021-05-20T11:36:47.0136338Z Step 11/32 : ENV NUGET_CREDENTIALPROVIDER_SESSIONTOKENCACHE_ENABLED true
2021-05-20T11:36:47.0340003Z ---> Running in dc9e064c144a
2021-05-20T11:36:48.0165125Z Removing intermediate container dc9e064c144a
2021-05-20T11:36:48.0166236Z ---> 2cb8ce18a003
2021-05-20T11:36:48.0166823Z Step 12/32 : ENV VSS_NUGET_EXTERNAL_FEED_ENDPOINTS "{\"endpointCredentials\": [{\"endpoint\":\"${AZURE_FEED}\", \"username\":\"docker\", \"password\":\"${NUGET_PAT}\"}]}"
2021-05-20T11:36:48.0346391Z ---> Running in 06e748e76592
2021-05-20T11:36:49.0167180Z Removing intermediate container 06e748e76592
2021-05-20T11:36:49.0168216Z ---> 21dff5c2a393
2021-05-20T11:36:49.0168806Z Step 13/32 : RUN wget -O - https://aka.ms/install-artifacts-credprovider.sh
2021-05-20T11:36:49.0331863Z ---> Running in 653d535fd87e
2021-05-20T11:36:50.5360687Z [91mConnecting to aka.ms (104.67.209.176:443)
2021-05-20T11:36:50.9255227Z [0m[91mConnecting to raw.githubusercontent.com (185.199.109.133:443)
2021-05-20T11:36:51.0266615Z [0m[91mwriting to stdout
2021-05-20T11:36:51.0269224Z [0m#!/usr/bin/env bash
2021-05-20T11:36:51.0269620Z # DESCRIPTION: A simple shell script designed to fetch the latest version
2021-05-20T11:36:51.0270020Z # of the artifacts credential provider plugin for dotnet and
2021-05-20T11:36:51.0270333Z # install it into $HOME/.nuget/plugins.
2021-05-20T11:36:51.0270979Z # SEE: https://github.com/Microsoft/artifacts-credprovider/blob/master/README.md
2021-05-20T11:36:51.0271177Z
2021-05-20T11:36:51.0271529Z REPO="Microsoft/artifacts-credprovider"
2021-05-20T11:36:51.0271833Z FILE="Microsoft.NuGet.CredentialProvider.tar.gz"
2021-05-20T11:36:51.0272080Z VERSION="latest"
2021-05-20T11:36:51.0272612Z # URL pattern documented at https://help.github.com/en/articles/linking-to-releases as of 2019-03-29
2021-05-20T11:36:51.0273028Z URI="https://github.com/$REPO/releases/$VERSION/download/$FILE"
2021-05-20T11:36:51.0273327Z NUGET_PLUGIN_DIR="$HOME/.nuget/plugins"
2021-05-20T11:36:51.0273475Z
2021-05-20T11:36:51.0273677Z # Ensure plugin directory exists
2021-05-20T11:36:51.0274069Z if [ ! -d "${NUGET_PLUGIN_DIR}" ]; then
2021-05-20T11:36:51.0274767Z echo "INFO: Creating the nuget plugin directory (i.e. ${NUGET_PLUGIN_DIR}). "
2021-05-20T11:36:51.0275283Z if ! mkdir -p "${NUGET_PLUGIN_DIR}"; then
2021-05-20T11:36:51.0275655Z echo "ERROR: Unable to create nuget plugins directory (i.e. ${NUGET_PLUGIN_DIR})."
2021-05-20T11:36:51.0275955Z exit 1
2021-05-20T11:36:51.0276136Z fi
2021-05-20T11:36:51.0276320Z fi
2021-05-20T11:36:51.0276403Z
2021-05-20T11:36:51.0276599Z echo "Downloading from $URI"
2021-05-20T11:36:51.0276893Z # Extract netcore from the .tar.gz into the plugin directory
2021-05-20T11:36:51.0277180Z
2021-05-20T11:36:51.0277502Z #Fetch the file
2021-05-20T11:36:51.0278259Z curl -H "Accept: application/octet-stream" \
2021-05-20T11:36:51.0278673Z -s \
2021-05-20T11:36:51.0279032Z -S \
2021-05-20T11:36:51.0279377Z -L \
2021-05-20T11:36:51.0279833Z "$URI" | tar xz -C "$HOME/.nuget/" "plugins/netcore"
2021-05-20T11:36:51.0280016Z
2021-05-20T11:36:51.0280338Z echo "INFO: credential provider netcore plugin extracted to $HOME/.nuget/"
2021-05-20T11:36:51.0291723Z [91m- 100% |********************************| 1213[0m[91m 0:00:00 ETA
2021-05-20T11:36:51.0292150Z written to stdout
2021-05-20T11:36:52.0145556Z [0mRemoving intermediate container 653d535fd87e
2021-05-20T11:36:52.0146179Z ---> 90962e0fe2f3
2021-05-20T11:36:52.0146481Z Step 14/32 : RUN printenv
2021-05-20T11:36:52.0341626Z ---> Running in de688137dee7
2021-05-20T11:36:52.3685737Z DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false
2021-05-20T11:36:52.3686185Z NUGET_CREDENTIALPROVIDER_SESSIONTOKENCACHE_ENABLED=true
2021-05-20T11:36:52.3686469Z HOSTNAME=de688137dee7
2021-05-20T11:36:52.3686745Z DOTNET_USE_POLLING_FILE_WATCHER=true
2021-05-20T11:36:52.3686993Z SHLVL=1
2021-05-20T11:36:52.3687187Z HOME=/root
2021-05-20T11:36:52.3687432Z DOTNET_RUNNING_IN_CONTAINER=true
2021-05-20T11:36:52.3687794Z AZURE_FEED=http://pkgs.dev.azure.com/mytestorganization/_packaging/mytestorganization/nuget/v3/index.json
2021-05-20T11:36:52.3688201Z NUGET_PAT=wz2ilhvt2urpzqlqlldd2f2hl6do77jkmreydrpmskwco3fc7sva
2021-05-20T11:36:52.3689296Z POWERSHELL_DISTRIBUTION_CHANNEL=PSDocker-DotnetCoreSDK-Alpine-3.13
2021-05-20T11:36:52.3689701Z PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
2021-05-20T11:36:52.3690173Z LANG=en_US.UTF-8
2021-05-20T11:36:52.3690539Z LC_ALL=en_US.UTF-8
2021-05-20T11:36:52.3690774Z ASPNETCORE_URLS=
2021-05-20T11:36:52.3691003Z PWD=/src
2021-05-20T11:36:52.3691618Z VSS_NUGET_EXTERNAL_FEED_ENDPOINTS={"endpointCredentials": [{"endpoint":"http://pkgs.dev.azure.com/mytestorganization/_packaging/mytestorganization/nuget/v3/index.json", "username":"docker", "password":"wz2ilhvt4ghjrpzqlqllxsda2hl6do77jkmreyvotsaskwco3fc7sva"}]}
2021-05-20T11:36:52.3692283Z NUGET_XMLDOC_MODE=skip
2021-05-20T11:36:53.0269908Z Removing intermediate container de688137dee7
2021-05-20T11:36:53.0277361Z ---> 47c3745c86a9
2021-05-20T11:36:53.0278468Z Step 15/32 : RUN dotnet restore --configfile NuGet.Config "MyAppService/MyAppService.csproj"
2021-05-20T11:36:53.0300480Z ---> Running in 7cb2aad61823
2021-05-20T11:36:54.4782539Z Determining projects to restore...
2021-05-20T11:36:55.5458935Z /usr/share/dotnet/sdk/3.1.409/NuGet.targets(128,5): error : Unable to load the service index for source https://pkgs.dev.azure.com/mytestorganization/_packaging/mytestorganization/nuget/v3/index.json. [/src/MyAppService/MyAppService.csproj]
2021-05-20T11:36:55.5459838Z /usr/share/dotnet/sdk/3.1.409/NuGet.targets(128,5): error : Response status code does not indicate success: 401 (Unauthorized). [/src/MyAppService/MyAppService.csproj]
2021-05-20T11:36:55.7208436Z The command '/bin/sh -c dotnet restore --configfile NuGet.Config "MyAppService/MyAppService.csproj"' returned a non-zero code: 1
2021-05-20T11:36:55.7348351Z ##[error]The command '/bin/sh -c dotnet restore --configfile NuGet.Config "MyAppService/MyAppService.csproj"' returned a non-zero code: 1
2021-05-20T11:36:55.7359274Z ##[error]The process '/usr/bin/docker' failed with exit code 1
2021-05-20T11:36:55.7376406Z ##[section]Finishing: build
I tried many thinks like give full acces token. So what im doing wrong?
Try to add verification information to your package source. Use packageSourceCredentials under custom nuget.config file:
Modify your nuget.config as:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="mytestorganization" value="https://pkgs.dev.azure.com/mytestorganization/_packaging/mytestorganization/nuget/v3/index.json" />
</packageSources>
<packageSourceCredentials>
<mytestorganization>
<add key="Username" value="xxxx" />
<add key="Password" value="xxxx" />
</mytestorganization>
</packageSourceCredentials>
</configuration>

Xcode test failing does not failed Github action pipeline

I have a Github Action pipeline:
name: default
on: [push]
jobs:
build:
runs-on: macOS-latest
steps:
- uses: actions/checkout#v1
- name: CocoaPod Install
run: pod install
- name: Force xcode 11
run: sudo xcode-select -switch /Applications/Xcode_11.1.app
- name: Test
run: ./pipelines.sh test
- name: Save report
uses: actions/upload-artifact#v1
with:
name: test_report
path: ./Test
And a script Shell:
function test
{
xcodebuild \
-workspace MyApp.xcworkspace \
-scheme DEBUG\ -\ MyApp \
-destination 'platform=iOS Simulator,name=iPhone 11' \
test
}
My problem is when i run my pipeline with failing test, the pipeline is marked as PASSED, which is a problem...
I have also check with fastlane, failing test does not fail the pipeline.
How can I make my pipeline as FAIL when test does not pass?
Cf screenshot for fastlane:
You need to return a non-zero value to fail the step.
Try adding this to the xcodebuild command.
xcodebuild -... || exit 1
There are some other solutions besides this at the following question.
How to get the return value of xcodebuild?
Update: Based on your comments that you would like steps afterwards to complete you can do the following.
Change your script to set an output containing the result of the xcodebuild command.
xcodebuild \
-workspace MyApp.xcworkspace \
-scheme DEBUG\ -\ MyApp \
-destination 'platform=iOS Simulator,name=iPhone 11' \
test
echo "::set-output name=result::$?"
Add an id to the step where this script is executed.
- name: Test
id: xcodebuild
run: ./pipelines.sh test
At the end of your workflow you can check if the tests did not pass and fail the workflow.
- name: Check Tests Passed
if: steps.xcodebuild.outputs.result != 0
run: exit 1

How to include sonarqube scan step in Google Cloud Build steps

I have a sonarqube server running on top of Azure and a CICD pipeline configured using Google cloud build on top of GCP. Do you have an idea about how to include the sonarqube connection information in my cloudbuild file as a custom build step? I'm using gradle to build my build and test my images.
There's a sonarqube community cloud builder: https://github.com/GoogleCloudPlatform/cloud-builders-community/tree/master/sonarqube
There is an example of using it as a step here: https://github.com/GoogleCloudPlatform/cloud-builders-community/blob/master/sonarqube/examples/cloudbuild.yaml
Below sample code worked for me
#static code analysis by sonarqube
- name: 'maven:3.6.1-jdk-8'
entrypoint: 'bash'
args:
- -c
- |
unset MAVEN_CONFIG \
&& echo "104.199.71.165 sonarqube.ct.blue.cdtapps.com" > /etc/hosts \
&& mvn sonar:sonar -q -Dsonar.login=5531b1a2d571c0482a3d45f605830e08ccf5f245 \
'-Dsonar.projectKey=odp.df.pubsub-sftp' \
'-Dsonar.projectName=ODP-DF-PUBSUB-SFTP' \
'-Dsonar.host.url=https://sonarqube.ct.blue.cdtapps.com' \
'-Dsonar.qualitygate.wait=true' \
'allow_failure: true'
dir: 'dataflows/generic/pubsub-sftp/src'
id: 'sonarqube-analysis'

Cloud formation lambda not picking jar from code build

I tried to use Code Pipeline to automate the code deployment. It uses Git Hub -> Code Build -> Cloud Formation as mentioned in wiki
AWS Automation of Lambda
I managed to get the pipeline run after few changes suggested by this thread
However whenever I am using the code pipeline, the Lambda test fails saying the class is not found.
In order to verify, I uploaded the jar directly in AWS lambda console and it worked fine.
I also verified the jar which is built by aws code build in the S3 "MyAppBuild" folder and it contains jar file in target/app-1.0-SNAPSHOT.jar in a zip file along with my SamTemplate.yml.
This is the SamTemplate.yml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Outputs the time
Parameters:
SourceBucket:
Type: String
Description: S3 bucket name for the CodeBuild artifact
SourceArtifact:
Type: String
Description: S3 object key for the CodeBuild artifact
Resources:
TimeFunction:
Type: AWS::Serverless::Function
Properties:
Handler: com.xxx.Hello::handleRequest
Runtime: java8
CodeUri:
Bucket: !Ref SourceBucket
Key: !Ref SourceArtifact
Events:
MyTimeApi:
Type: Api
Properties:
Path: /TimeResource
Method: GET
Here is the buildSpec.yaml
version: 0.2
phases:
build:
commands:
- echo Build started on `date`
- mvn test
post_build:
commands:
- echo Build completed on `date`
- mvn package
install:
commands:
- aws cloudformation package --template-file SamTemplate.yaml --s3-bucket codepipeline-us-east-1-xxxx
--output-template-file NewSamTemplate.yaml
artifacts:
type: zip
files:
- SamTemplate.yaml
- target/app-1.0-SNAPSHOT.jar
Any suggestions to try on?
I use maven.
Finally, after a few tries I found a probable solution for the packaging with aws code build, cloud formation, and lambda.
The whole point is that code build creates a wrapper zip of all files mentioned in artifacts:
This is the same zip file which must be given to aws lambda.
In order for aws lambda to accept a zip as valid, classes should be root folder, dependent libs should be in libs folder.
So I managed to do this as my build spec.
version: 0.2
phases:
install:
commands:
- aws cloudformation package --template-file SamTemplate.yaml --s3-bucket codepipeline-us-east-1-XXXXXXXX
--output-template-file NewSamTemplate.yaml
build:
commands:
- echo Build started on `date`
- gradle build clean
- gradle test
post_build:
commands:
- echo Build started on `date`
- gradle build
- mkdir -p deploy
- cp -r build/classes/main/* deploy/
- cp NewSamTemplate.yaml deploy/
- cp -r build/libs deploy/
- ls -ltr deploy
- ls -ltr build
- echo Build completed on `date`
- echo Build is complete
artifacts:
type : zip
files:
- '**/*'
base-directory : 'deploy'

Resources