CI/CD complains about ssh command not being found

I have a very simple Micronaut application with Java 14 in gitlab.com and a .gitlab-ci.yml file that looks like follows

variables:
  MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
  MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true"

image: maven:3.6.1-jdk-14

stages:
    - package
    - release
    - run

maven-package:
    stage: package
    script:
        - ./mvnw verify -Dmaven.repo.local=$MAVEN_USER_HOME
    artifacts:
        paths:
            - target/*.jar
        expire_in: 1 day

docker-push:
    only:
        - master
        - develop
    image: docker:latest
    services:
        - docker:dind
    variables:
        REGISTRY_URL: registry.gitlab.com
        DOCKER_HOST: tcp://docker:2375
        DOCKER_DRIVER: overlay2
        IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
    stage: release
    dependencies:
        - maven-package
    before_script:
        - docker info
        - cp target/*.jar .
    script:
        - docker login -u "gitlab-ci-token" -p "$CI_BUILD_TOKEN" $REGISTRY_URL
        - docker build -t $IMAGE_TAG .
        - docker push $IMAGE_TAG

docker-run:
    only:
        - master
    stage: run
    dependencies:
        - docker-push
    script:
        - ssh root@$DEPLOYMENT_SERVER_IP "./restart"

The first 2 jobs finish successfully, but the run job fails with
/usr/bin/bash: line 109: ssh: command not found.

Is there something I’m missing? am I overdoing the pipelines?
Thanks!

Maybe there is no ssh client in your Docker image? I would try to add

apt update && apt install  openssh-client

in the beginning of the script.

then I get
/usr/bin/bash: line 105: apt: command not found

Then write “apt-get” instead of “apt”

I get the same error. Could it be that the image maven:3.6.1-jdk-14 is the issue? should I use another image like alpine?

Yes, try it. I think this is a good idea. AFAIU, you don’t need Maven in your docker-run job.

adding image: adoptopenjdk/openjdk14:alpine-slim fixed the issue :slight_smile: thanks!

Glad to hear. In the end, what had worked, apt-get or apt (or the image already contained ssh)?

I had to add the apt-get part :slight_smile: