Uso il plug-in Jenkins PowerShell per creare un progetto.Il plug-in Jenkins PowerShell viene sempre creato correttamente
Tuttavia, ho trovato che Jenkins considera sempre la mia build di successo, indipendentemente da ciò che digito nel comando Windows PowerShell
.
Ecco un esempio:
Come si può vedere, asdf
non è un comando legale. Jenkins dovrebbe darmi FAILURE
dopo la costruzione.
Ma l'uscita della console mi dà:
Started by user admin
Building in workspace C:\Users\Administrator\.jenkins\jobs\Test\workspace
[workspace] $ powershell.exe -NonInteractive -ExecutionPolicy ByPass "& 'C:\Users\ADMINI~1\AppData\Local\Temp\hudson2092642221832331776.ps1'"
The term 'asdf' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\ADMINI~1\AppData\Local\Temp\hudson2092642221832331776.ps1:1 char:5
+ asdf <<<<
+ CategoryInfo : ObjectNotFound: (asdf:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Finished: SUCCESS
penso che il risultato dell'esecuzione di PowerShell dovrebbe dipendere $lastexitcode
.
Si tratta di un errore del plug-in PowerShell?
Nello script PowerShell quando si verifica un errore, utilizzare "exit x" dove x è un numero diverso da zero. Vedi se Jenkins ritiene che sia fallito allora. – DanL
Sì, Jenkins considera "uscita 1" come fallita. – Brian
Quindi modificare gli script per uscire con un codice di errore diverso da zero se si verifica un errore. Se vuoi che dipenda solo da $ lastexitcode allora in fondo al tuo script controlla $ lastexitcode e usa exit 1 se applicabile. – DanL