I’m writing a Jenkins pipeline, the script has a stage for stopping the process, if it exists. The script runs and supposedly successfully kills the process, without any errors, etc. But it doesn’t actually kill him. I rewrote this stage into a local batch file and ran it as an administrator, and this process died. I would like to know,
how can I fix my problem? so that jenkins itself can kill the process, perhaps it does not have enough rights to do this, I don’t know. Below is the script:
steps {
script {
bat """
echo %DATE% %TIME% - Checking if ${SERVICE_NAME} process is running >> ${DEPLOY_LOG}
set PROCESS_FOUND=false
for /f "tokens=2 delims==" %%i in ('wmic process where "name='${SERVICE_NAME}.exe'" get ProcessId /format:list 2^>nul') do (
echo %DATE% %TIME% - Process ${SERVICE_NAME} found with PID %%i >> ${DEPLOY_LOG}
set PROCESS_FOUND=true
)
echo %DATE% %TIME% - Process found: %PROCESS_FOUND% >> ${DEPLOY_LOG}
"""
bat """
echo %DATE% %TIME% - Attempting to stop ${SERVICE_NAME} process >> ${DEPLOY_LOG}
if "%PROCESS_FOUND%"=="true" (
for /f "tokens=2 delims==" %%i in ('wmic process where "name='${SERVICE_NAME}.exe'" get ProcessId /format:list 2^>nul') do (
wmic process where processid=%%i delete
if %errorlevel% equ 0 (
echo %DATE% %TIME% - Process ${SERVICE_NAME} stopped successfully >> ${DEPLOY_LOG}
) else (
echo %DATE% %TIME% - Couldn't stop process ${SERVICE_NAME} >> ${DEPLOY_LOG}
)
)
) else (
echo %DATE% %TIME% - No process ${SERVICE_NAME} found to stop >> ${DEPLOY_LOG}
)
"""
}
}
}```
Написал собственный bat файл для остановки процесса.
Владислав Лисицкий is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1