Jenkins Pipeline Checkout to the latest release tag

34 views Asked by At

I am working on establishing a Jenkins pipeline that compiles a React application and transfers the build directory to a remote server. The build process is based on the master branch, and authentication is configured within the pipeline settings. The following is the existing content of the Jenkins file.

pipeline {
    agent {
        docker {
            label 'linux-builder'
            image 'node:14'
            args '-p 3000:3000 -u root'
        }
    }
    stages {
        stage('Build') {
            steps {
                sh 'apt update; apt install rsync -y'
                sh 'cat /etc/os-release'
                sh 'node -v'
                sh 'npm -v'
                sh 'npm install'
                sh 'CI=false npm run build
            }
        }
        stage('Deploy') {
            steps {
                // Deployment script
                }
            }    
        }
    }
}

I need to modify the Jenkins configuration to fetch the latest release tag from GitHub.

I discovered the checkout step outlined in forums, I am encountering authentication issues with GitHub. Also I don't want the tage name to be hardcoded.

    stages {
        stage('checkout') {
            steps {
                checkout([$class: 'GitSCM', branches: [[name: '2.0.2']],
                    userRemoteConfigs: [[url: '[email protected]:reponae.git',
                                       credentialsId: 'id']]
                ])
            }
        }

Any suggetions is much appreciated.

0

There are 0 answers