Domanda

Tentativo di inviare un Changelist senza file è considerato da Perforce per essere un errore (p4 submit ... restituisce il codice di uscita 1). Ciò causa una build di integrazione periodica per fallire sul nostro server di build (stiamo usando Sistema di impulso di Zutubi ); In questo caso preferirei avere la build successo , possibilmente con un avvertimento.

Pulse ha funzionalità di rimapping del codice di uscita, ma la perforce non sembra disambiguare tra una mancata invio di un changelist vuoto e qualsiasi altro errore di invenzione (tale errore di trigger di convalida, che I DO Vuoi fallire la build).

La soluzione immediatamente ovvia (ma, nella mia mente, inelegante) che viene in mente è di avvolgere l'esecuzione di p4 submit in un file batch che prima controlla se il changelanista di destinazione è vuoto contando le linee di uscita da p4 opened - o semplicemente analizzare l'output di p4 submit per il messaggio "NO Files" e restituire correttamente dal file batch.

Ci sono tecniche migliori per gestire questo che non sto vedendo?

È stato utile?

Soluzione

There are probably no good techniques just with Perforce, if I am understanding your problem correctly. The issue, as you have seen, is that the return codes from perforce command line runs are, well, ambiguous. Is a submission of an empty changelist really an error? Maybe, maybe not - might depend on who you ask.

It's is not really that advisable to look at return codes from 'p4' commands. Your best bet as you have suggested is to parse the output of the command and then do what you need to from there.

Most commands now support the -ztag option (see 'p4 help usage'), which will could make parsing the output a bit easier, depending on what you want to do. If your case, it is probably sufficient enough to just look for the text in the output and then decide what to do from there.

Altri suggerimenti

Before attempting to submit a changelist, you could first attempt to delete it.

p4 change -d ###

This operation will only succeed if the changelist is empty, so don't submit it (you have just deleted it). If it fails, there are files in the changelist, so go ahead and submit them.

However, if you use jobs, this won't work for you because you can't delete a changelist that has a job attached to it, even if it's empty.

I did ultimately end up parsing the output in a batch file, using something like this:

for /f "delims=" %%I in ('p4 submit -d "<message>" 2^>^&1 1^>NUL') do    
set SUBMIT_OUTPUT=%%I
if "%SUBMIT_OUTPUT%"=="No files to submit from the default changelist." exit /b 0

This is necessary since p4's "no files" message is actually writting to stderr normally. If the output is the message I consider "safe" I exit with a zero exit code, otherwise the script will continue with whatever error level was set by the p4 command.

Note that the "no files" message for a numbered changelist is slightly different, if you're using that.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top