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
pythonlabel is assigned to thatDockerfileagent?python3in the command, but the error message sayspython- I think you're editing the wrong file, or something like that.