Visua studio build event and microsoft signtool

0

I have a visual studio C++ project that is built in Team City environment. In its post build event, I call to a script to sign the binary using microsoft signtool.exe, the script is as bellow:

@echo off
SET SIGN_ATTEMPTS=0
SET MAX_SIGN_ATTEMPTS=60
SET SIGN_TOOL="C:\Program Files\Microsoft SDKs\Windows\v7.1A\Bin\signtool.exe"

if %1=="" goto done

if [%SIGN_TOOL%]==[] (
    echo "signtool is not specified, then do not sign %1"
    goto done
)

::Try to verify the signature first
cmd /c %SIGN_TOOL% verify /pa /q %1
IF %ERRORLEVEL%==0 goto done

:normalsign
cmd /c %SIGN_TOOL% sign /fd SHA256 /a /t http://timestamp.verisign.com/scripts/timestamp.dll /v %1

IF NOT %ERRORLEVEL%==0 (
    ECHO last errror: %ERRORLEVEL%
    SET /a SIGN_ATTEMPTS+=1
    IF NOT %SIGN_ATTEMPTS%==%MAX_SIGN_ATTEMPTS% (
        ECHO Failed to sign %1 at %SIGN_ATTEMPTS% attempts
        ping 1.1.1.1 -n 1 -w 2000 > NUL
        GOTO normalsign
    ) ELSE ( 
        ECHO Give up after %MAX_SIGN_ATTEMPTS% attempts
        GOTO failed
    )
) ELSE (
    GOTO done
)

:done
    ECHO Succesfully signed %1
    ECHO last error is %ERRORLEVEL%
    EXIT 0

:failed
    ECHO Failed signning %1 with last error: %ERRORLEVEL%
    EXIT 10

as the above logic, it sometimes failed at first call to SIGN_TOOL, with error: EXEC error information: "SignerTimeStamp() failed." (-2147012894/0x80072ee2), but after second attempts, it signed successfully, then the script exited. But after the success at second trial, Visual Studio still considered it as a failure, then my project build got failed.

I try to put EXIT 0 for successful cases, but Team City still reports error: :VCEnd" exited with code -1.

Could you please explain me why is that? And how I can get the VS build success in case of success in second(and may later) signing attempt??

thanks,

visual-studio
batch-file
cmd
teamcity
asked on Stack Overflow May 27, 2020 by van con Nguyen • edited May 28, 2020 by van con Nguyen

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0