jenkins job,agents,nodes

Table of contents

No heading

No headings in the article.

add nodes

in host, public ip of, demo-agent server

add credentials

and after fill press add button. and now your new creadential add. you can also add credential

after save configure, your agent successfully connect and you see you node screen like this-

if your agent not in sync. then refresh nodes or check log. if in logs give some error then generate new key because maximum time this error fix using new key

New key generate- go to master terminal and in .ssh directory then .

ssh-keygen -t ed25519

after press enter 3 times your jenkins private and public key generate and now you follow previous steps for connect agent. then your agent node successfully connect and sync. this time.

pipeline for agent.

open master jenkins and create a new jobs .

pipeline {
    agent {label 'agent-2'} // any agent name 
    stages{
        stage ('code clone'){
            steps {
                git url: 'https://github.com/Hemantjangir53/django-notes-app.git', branch: 'main'
            }
        }
        stage ('Build'){
            steps {
                echo "code build"
            }
        }
        stage ('push'){
            steps {
                echo "deploy"
            }
        }
    }
}

for push to docker Hub we need to install environment plugins

after install and restart jenkins, set environment variable

final groovy code

pipeline {
    agent {label 'agent-2'}
    stages{
        stage ('code clone'){
            steps {
                git url: 'https://github.com/Hemantjangir53/django-notes-app.git', branch: 'main'
            }
        }
        stage ('Build'){
            steps {
                sh 'docker build . -t django-notes'
                echo "code build"
            }
        }
        stage ('push to docker HUb'){
            steps {
                withCredentials([
                        usernamePassword(
                            credentialsId: 'dockerHub',
                            usernameVariable: 'DOCKERHUB_USERNAME',
                            passwordVariable: 'DOCKERHUB_PASSWORD')]){
                                sh "docker tag django-notes ${env.DOCKERHUB_USERNAME}/django-notes "
                                sh "docker login -u ${env.DOCKERHUB_USERNAME} -p ${env.DOCKERHUB_PASSWORD}"
                                sh "docker push ${env.DOCKERHUB_USERNAME}/django-notes:latest"
                    }
            }
        }
        stage ('deploy'){
            steps {
                sh 'docker-compose down && docker-compose up -d '
                echo "deploy"
            }
        }

    }
}

Build triggers- for autorun after commit on github

GITScm(Git Source Code Management) polling

now any commit on github code and you can see pipeline automatically run

pipeline script from SCM

create new Jenkins file on gitHub and after any changes on code and commit this, you can see stage view

here now our all code run via Declarative CI/CD(Continuous Integration/Continuous Delivery).

we can see code management work in the master server But docker images and docker container available in agent server.