1

I get the same error with sh 'python --version' and sh 'python3 --version' And I don't know why Jenkins doesn't recognize the command when the Dockerfile image has python installed, my Jenkins version: 2.319.3 I added the label to the node, I tried without label in the pipeline... Echo and ls command works and I don't know if I understand it very much hahahaha HELP!

My pipeline:

pipeline {
    agent {
        label 'python'
    }
    stages {
        stage ('Test') {
            steps {
                sh 'echo Aloha!!!!!'
            }
        }
        stage ('Is there any python?') {
            steps {
                sh 'python3 --version'
            }
        }
    }
}

My Dockerfile

FROM ubuntu:21.10

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
    apt-get install -qy git wget software-properties-common openssh-server && \
    sed -i 's|session    required     pam_loginuid.so|session    optional     pam_loginuid.so|g' /etc/pam.d/sshd && \
    mkdir -p /var/run/sshd && \
    apt-get install -qy openjdk-8-jdk && \
    apt-get install -qy maven && \
    apt-get install -qy apt-utils && \
    useradd -ms /bin/bash jenkins && \
    echo "jenkins:jenkins" | chpasswd && \
    mkdir /home/jenkins/.m2

RUN mkdir /home/jenkins/.ssh/ && \
    touch /home/jenkins/.ssh/authorized_keys

RUN chown -R jenkins:jenkins /home/jenkins/.m2/ && \
    chown -R jenkins:jenkins /home/jenkins/.ssh/

RUN apt-get install python3

RUN apt-get update && apt-get install python3-pip python3.9-venv -y

RUN cd "$(dirname $(which python3))" && \
    ln -s idle3 idle && \
    ln -s pydoc3 pydoc && \
    ln -s python3 python && \
    ln -s python3-config python-config

COPY .pypirc /home/jenkins/

EXPOSE 22

CMD ["/usr/sbin/sshd", "-D"]

Jenkins

[Pipeline] { (Is there any python?)
[Pipeline] sh
+ python3 --version
/var/jenkins_home/workspace/Jobs/Pipeline Github Example@tmp/durable-a28fa974/script.sh: 1: python3: not found
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 127
Finished: FAILURE
4
  • Are you certain the python label is assigned to that Dockerfile agent? Commented May 20, 2022 at 15:14
  • Not assigned? Where is it supposed to be assigned? In the pipeline says label 'python' and I even assigned it to the node. Do I have to assign in the dockerfile??? Commented May 20, 2022 at 15:22
  • Your pipeline says python3 in the command, but the error message says python - I think you're editing the wrong file, or something like that. Commented May 20, 2022 at 15:49
  • that's cuz I've tried with both... but I get the same error putting python3 or python... and it's the same file... [Pipeline] { (Is there any python?) [Pipeline] sh + python3 --version /var/jenkins_home/workspace/Jobs/Pipeline Github Example@tmp/durable-a28fa974/script.sh: 1: python3: not found [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline ERROR: script returned exit code 127 Finished: FAILURE Commented May 20, 2022 at 15:54

1 Answer 1

1

Jenkins agent label represents one or one group worker node(s) on which Jenkins master will schedule job/pipeline run.

Therefore your pipeline is assigned to run on worker node 'python', the error told you it can't find python executable on the worker node.

You need to register machine/vm to Jenkins master to make it serve as Jenkins worker node, when register, you can specify labels for the worker node, then you can use label to reference worker node in your job/pipeline.

One option is to prepare python on worker node 'python'

Another option is to use your Dockerfile as agent for whole pipeline or single stage. More detail: https://www.jenkins.io/doc/book/pipeline/syntax/#agent

Sign up to request clarification or add additional context in comments.

1 Comment

Hi Yong thanks for answering... I already opened docker's API and I configured a docker cloud on Jenkins, the test connection is ok, and also I configured the docker agent with the label python and with that dockerfile, the connect method is ssh with credentials so... I don't know why it ain't working...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.