Home>

Hello everyone! Tell me please.

I'm using Jenkins to build a project that's running in a docker container and I've run into a problem.

When executing this piece of code:

stage('deploy front') {
        when { equals expected: 'do', actual: buildFront }
        agent {docker{image 'ebiwd/alpine-ssh'}}
        steps{
            sh 'chmod 400 .iac/privatekey'
            sh "ssh -i .iac/privatekey [email protected] 'cd /opt/docker/test &
&
 docker-compose pull nginx &
&
 docker-compose up -d --force-recreate --no-deps nginx '"
        }
    }

I get an error:

+ ssh -i .iac/privatekey [email protected]

Pseudo-terminal will not be allocated because stdin is not a terminal.

Warning: Permanently added '134.209.181.163' (ECDSA) to the list of known hosts.

bind: No such file or directory

At the same time, if you execute the following script manually in the container, then everything works

ssh -i .iac/privatekey [email protected]

I start the container itself using docker-compose.yaml

version: '3.1'
services:
  jenkins:
    image:jenkins/jenkins:2.277.1-lts
    container_name: jenkins
    hostname: jenkins
    restart: always
    user: root
    privileged: true
    ports:
      -172.17.0.1:8070:8080
      -50000:50000
    volumes:
      -/opt/docker/jenkins/home:/var/jenkins_home
      -/etc/timezone:/etc/timezone
      -/usr/bin/docker:/usr/bin/docker
      -/etc/localtime:/etc/localtime
      -/var/run/docker.sock: /var/run/docker.sock

What could be the problem?

At the very least, the problem is that by using a command in this form, you tell ssh to start an interactive session from a script, i.e. from a context that does not imply interactivity. From the console, you start the shell and everything works, but what do you expect from this command when you run the script from Jenkins?

Roman Konoval2022-02-03 10:01:42

In fact, initially the script is a little longer, I shortened it trying to localize the error. I will now return the original script by editing the question. Can you please tell me how can I use this script without interactivity?

Anton Danilov2022-02-03 10:17:31