We have a GitLab Pipeline with the following job which runs inside a Docker Container that has Java installed:
generate_openapi_server_code:
image: java:17
stage: validate
tags:
- test
script:
- "wget https://<artifactory-host-url>/artifactory/Maven-Central-remote-cache/org/openapitools/openapi-generator-cli/6.3.0/openapi-generator-cli-6.3.0.jar -O openapi-generator-cli.jar"
- "java -jar openapi-generator-cli.jar generate -g spring -o out -i dispo.yaml | sed '/WARN/q1'"
As you can see in the first step it downloads the Java Lib from our Maven Repo and then starts the program. In order we can validate the outcome of the program we try to check the console output with the sed
command tool. The problem is that sed
is not available in that image so the job fails with: sed: missing command
.
Do you have an idea how to check the Java’s output in a container? Do you know a better container which has all tools at hand, i.e. Java 17 and sed?
2
Answers
In the end the image had at least the
awk
program installed and so I could check Java's output byawk
's help for a special character sequence and if there were matches then exit the program right away with exit code 1:Strange, I just checked the
amazoncorretto:17
locally and it seems to have thesed
command. You can, however, build your own docker image which is based onamazoncorretto:17
(or any image for that matter) and install sed (even though when I checked locally it is already present). You can also use"java -jar openapi-generator-cli.jar generate -g spring -o out -i dispo.yaml | grep -q 'WARN' && exit 1"
which should do the same. (I would assumegrep
is already present)