Jenkins pipeline with a Docker image

Hello! First question in here! I’m trying to learn about Jenkins and i’m stumbling with some problems with creating a pipeline with Docker.

This is my Dockerfile:

FROM ubuntu:24.04

RUN apt-get update && apt-get install --no-install-recommends -y \
     libssl-dev \
     zlib1g-dev \
     cmake \
     pkg-config \
     g++ \
     gcc \
     git \
     fontconfig \
     make && \
     apt-get clean


This is my Jenkins pipeline file:

pipeline {
    agent any
    stages {
        stage('Build') {
            agent {
                docker {
                    image 'mydocker:latest'
            steps {
                sh 'git --version'

Git version command returns error with “git not found”. Running “sh cat /etc/lsb-release” instead outputs ubuntu version 22.04 which is the one I’m using as a host…

What i am missing in here? Thanks!

Hello @Arreme ,
It’s great that you ask here. I’m also the new here and I’ve been learning Jenkins as well.
Untill no one else didn’t reply to your message I can propose to check out the following steps.

So, if you’d like to try I may suggest you to install the Git plugins if it wasn’t installed yet that you can check in "Manage Jenkins > Plugins > Installed plugins or to install it > Available plugins

In my case I’ve installed Git plugin when when was created the image in this way:

RUN jenkins-plugin-cli --plugins “git:5.2.1 github:”

Then I added the following stage in order to connect to Source Code Management, that is the URL link to remote repo on GitHub:

stage(‘Checkout Scm’) {
steps {
git branch: ‘main’, url: ‘

Make sure to replace the your_user_name and your_repository_name with yours.
In my case it works, however I’ve used as a base image Jenkins/Jenkins and added other dependencies as well, although it may not make any difference.

Best of luck :slight_smile: