Jenkins Rerun Old Build with Specific Commit I am pretty new to jenkins and trying to figure out the best way to accomplish rollbacks.  Currently this is my pipeline:


Obtain a webhook from beanstalk (git versioning)
Build the project
Obtain the build artifact and deploy to Azure


This is working great - the last thing I would like to solve is being able to rollback the project to a specific build. 

When I do a "replay" however, it doesn't grab the actual commit the build ran on - it grabs the current commit in the repo.  So it doesn't build the project from the commit it originally ran on - but the latest commit in the repo. 

pipeline {
agent any
stages {

    stage('Install Dependenciess') {
        steps {
            bat'npm install'
        }
    }

    stage('Build the Project') {
        steps {
            bat'npm run build'
        }
    }

    stage('Deploy to Azure Prod') {
        when {
            environment name: 'REPOSITORY_BRANCH', value: 'master'
            beforeAgent true
        }
        steps {

            timeout(time:5, unit: 'DAYS') {
                input message: 'Approve Deployment?'
            }

            azureWebAppPublish azureCredentialsId: env.AZURE_CRED_ID,
            resourceGroup: env.RES_GROUP, 
            appName: env.WEB_APP, 
            filePath: "**/*.*",
            sourceDirectory: "build"
        }
    }

    stage('Deploy to Azure Development') {
        when {
            environment name: 'REPOSITORY_BRANCH', value: 'development'
            beforeAgent true
        }
        steps {

            azureWebAppPublish azureCredentialsId: env.AZURE_CRED_ID,
            resourceGroup: env.RES_GROUP, 
            appName: env.WEB_APP, 
            filePath: "**/*.*",
            sourceDirectory: "build"
        }
    }

}

post {
    always {
        archiveArtifacts artifacts: "build/**/*.*", onlyIfSuccessful: true
        cleanWs()
    }

    success {
        mail bcc: '', body: "&lt;b&gt;Example&lt;/b&gt;&lt;br&gt;Project: ${env.JOB_NAME} &lt;br&gt;Build Number: ${env.BUILD_NUMBER} &lt;br&gt; URL de build: ${env.BUILD_URL}", cc: '', charset: 'UTF-8', from: '', mimeType: 'text/html', replyTo: '', subject: "ERROR CI: Project name -&gt; ${env.JOB_NAME}", to: "";
    }

}


}
As a short term solution you can replay you last good build. Read the docs for more information

Update: There is a bug , so the proposed way will work only in multibranch pipeline. So as a short term solution you can convert your job to a multibranch pipeline and to use a replay when it’s needed 

As a long term solution I would separate build and deployment job and store the build artifact in private npm registry. In that way you can always pick whatever version is needed to deploy