[JENKINS][IISSERVER] The process cannot access the file because it is being used by another process

29 views Asked by At

I have API in .NET 8.0 hosted on IIS server & operating system is Microsoft Windows server 2016.

When I run my Jenkins job then after a build stage, I try to deploy that files by bat 'scp -r G:/Source/* "G:/Destination/" ', but it throwing error as "The process cannot access the file because it is being used by another process." and if I manually copy that files and paste in our deployment directory then it successfully deployed.What does this mean, and what can I do about it?

Pipeline For Jenkin

pipeline {
    agent {
           label 'windows02'
    }
    stages {
        stage('delete') {
            steps {
                bat 'rmdir /s /q | echo y'
            }
        }
        stage('clone') {
            steps {
                git branch: 'UAT', credentialsId: 'JENKINS_TOKEN_GIT', url: 'https://gitlink.com'
            }
        }
       stage('Stop_website') {
           steps {
               bat '''
               C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe Stop-IISSite -Name "website" -Confirm:$false
               '''
           }
       }
       stage('build') {
            steps {
                   bat 'msbuild PROJECT.sln  /t:restore /t:Rebuild /p:outdir="G:/Source/" /p:Platform="Any CPU"' 
            }
       }

       stage ('Check website status') {
           steps {
               script {
                   def commandOutput = bat(script: 'C:\\Windows\\System32\\inetsrv\\appcmd.exe list site website', returnStdout: true).trim()
                   def searchString = 'SITE "website" (id:22,bindings:http/110.456.741.1.2:50060:,state:Stopped)'
                   env.CONDITION_MET = commandOutput.contains(searchString) ? 'true' : 'false'
                   if (commandOutput.contains(searchString)) {
                       echo "website successfully stopped "
                   } else {
                       error "website not stopped"
                   }
               }
           }
       }
       stage('Deploy') {
           steps {
               bat 'scp -r G:/Source/* "G:/Destination/"'
           }
       }
       stage('Start_website') {
           steps {
               bat '''
               C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe Start-IISSite -Name "website"
               '''
           }
       }
    }
}
1

There are 1 answers

1
Ghanshyam Baravaliya On BEST ANSWER

I add stop app pool to my script. It works.

Stop-WebAppPool -Name [ApplicationPoolName]