Home > Back-end >  Jenkins not deploying the latest github commit code
Jenkins not deploying the latest github commit code

Time:10-12

I'm trying to get Jenkins to deploy the latest code from github branch to my app server. When I push to my release branch, however, the latest commit code doesn't get deployed. Jenkins seems to deploy some older commit of mine. When I print the Branch_Name and Git_Commit I get the correct branch and commit id, so I'm not sure where I'm going wrong. Currently using a Jenkins 2.319.2 server.

The latest GitHub commit code gets pushed to the Jenkins Server WORKSPACE directory which looks like this C:\Program Files (x86)\Jenkins\workspace\PROJ_release. In the Workspace directory I confirmed that the latest commit changes are there. Somewhere between the Jenkins server and deploying to the app server seems to not get the latest commit changes.

Below is my Jenkins file:

def url = ""
def branch = env.BRANCH_NAME

def msdeploy =  'C:\\Program Files (x86)\\IIS\\Microsoft Web Deploy V3'

if (branch == "master"|| branch == "release") {
    node {

     // get dontnet.exe reference
      environment {
        dotnet = 'C:\\Program Files\\dotnet\\sdk\\2.1.803\\dotnet.exe'
        version = "${env.BUILD_NUMBER}"
      }
     // use nodejs 10.0.0 configured in global tools
     env.NODEJS_HOME = "${tool 'NodeJS10.0.0'}"
     env.PATH="${env.NODEJS_HOME};${env.PATH};"

      stage("Clean Workspace"){
       cleanWs()
    }

    stage('Pre Check'){
           env.GIT_COMMIT = checkout(scm).GIT_COMMIT
           env.type = ""

          // Only allow push to dev(master) and test(release)
          if (branch == "master") {
            url = 'mymasterurl'
                    echo("Preceding with CI options for dev")
                    env.type = "Dev"
                } else if (branch == "release"){
            url = 'myreleaseurl'

                    echo("Preceding with CI options for highside prod")
                    env.type = "Release"
                }
      }

    stage('Checkout/Clone Repository') {
                checkout scm
        }

    stage('Restore'){
              bat '%dotnet% dotnet restore PROJ.csproj'

        }

    stage('Build/Deploy'){
          withCredentials([usernamePassword(credentialsId: 'WEBDEPLOY_SRV_ACCOUNT', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD'),
                          string(credentialsId:'PROJ_AD_PASSWORD',variable: 'AD_PASSWORD')]) {
                def randomKey = UUID.randomUUID()
                                   .toString()
                                   .toUpperCase()
                def input = readJSON file: 'appsettings.json'
                //add Secrets
                input['TOKEN']['SECURITYKEY'] = randomKey
                input['AD_SERVICE_ACCOUNT']['USERNAME'] = env.USERNAME
                input['AD_SERVICE_ACCOUNT']['PASSWORD'] = env.PASSWORD
                echo "app settings: ${input}"
                // add build info to environment ts file for front end
                powershell ("""
                  (Get-Content .\\ClientApp\\environments\\environment.prod.ts).replace('%BUILD%',  "${env.BUILD_NUMBER}") | Set-Content  .\\ClientApp\\environments\\environment.prod.ts
                   (Get-Content .\\ClientApp\\environments\\environment.prod.ts).replace('%COMMIT%', "${env.GIT_COMMIT}") | Set-Content  .\\ClientApp\\environments\\environment.prod.ts
                   (Get-Content .\\ClientApp\\environments\\environment.prod.ts).replace('           
  • Related