Commands can be found in local via docker run but not in pieline docker container

Hi, I have created a docker image using this script:

FROM centos:7

RUN yum install -y \
    wget \
    git \
    make \
    tar \
    centos-release-scl \
    sudo

RUN mkdir -p /root/.ssh && \
cd /root/.ssh && \
wget http://192.168.111.64/env/auto-keys.tar && \
tar -xvf auto-keys.tar

RUN cd /root && wget https://repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh

RUN cd /root && sudo chmod 777 Anaconda3-2020.02-Linux-x86_64.sh && \
sudo ./Anaconda3-2020.02-Linux-x86_64.sh -b -p /root/anaconda3 && \
sudo ln -fs /root/anaconda3/bin/python /usr/bin/python3 && \
sudo ln -fs /root/anaconda3/bin/python /bin/python3 && \
rm -fr Anaconda3-2020.02-Linux-x86_64.sh

RUN cd /usr/local && \
wget http://192.168.111.64/env/gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu.tar.xz && \
tar -xvf gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu.tar.xz && \
rm -rf gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu.tar.xz

RUN cd /usr/local && \
wget http://192.168.111.64/env/gcc-arm-8.3-2019.03-x86_64-aarch64-elf.tar.xz && \
tar -xvf gcc-arm-8.3-2019.03-x86_64-aarch64-elf.tar.xz && \
rm -rf gcc-arm-8.3-2019.03-x86_64-aarch64-elf.tar.xz

RUN yum install -y \
    sshpass \
    devtoolset-8

RUN yum install -y openssl

RUN echo 'source /opt/rh/devtoolset-8/enable' | sudo tee /etc/profile.d/gcc-version.sh && source /etc/profile.d/gcc-version.sh
# RUN rm -rf /usr/bin/gcc

# RUN sudo ln -s /opt/rh/devtoolset-8/root/bin/gcc /usr/bin/gcc

ENV PATH /usr/local/gcc-arm-8.3-2019.03-x86_64-aarch64-linux-gnu/bin:${PATH}
ENV PATH /usr/local/gcc-arm-8.3-2019.03-x86_64-aarch64-elf/bin:${PATH}
# ENV PATH /opt/rh/devtoolset-8/root/bin/gcc:${PATH}

# RUN cd ~ && sed -i '$aexport PATH=$PATH:/usr/local/sbin:/usr/sbin' .bashrc && source .bashrc

This is my pipeline:

node('192.168.111.134'){
    def myImage
    myImage = docker.image 'prbuild:v7'
    stage('inside'){
        
        myImage.inside{
             sh '''
                        cd /root/${project}
                        git pull
                        git branch
                        ./quince_x86-64_wout_build_b58R.sh

                    '''
        }
    }

}

The error I came across

10:45:10  /bin/sh: g++: command not found
10:45:10  /bin/sh: g++: command not found
10:45:10  /bin/sh: g++: command not found
10:45:10  /bin/sh: g++: command not found
10:45:10  /bin/sh: g++: command not found
10:45:10  /bin/sh: g++: command not found
10:45:10  /bin/sh: g++: command not found
10:45:10  /bin/sh: g++: command not found
10:45:10  /bin/sh: g++: command not found

The question is I can run these scripts on my local container correctly but it show /bin/sh: g++: command not found when I am running the same script in Jenkins

The problem probably your PATH setting via ENV ( it will not do what you expect…)
I would create a (sh)-script for setting up the environment and call it from the jenkins job.

1 Like