Inside Build.xml
<target name="EncryptDB">
<!-- Paramters
DB_To_Encrypt_Dir = REQUIRED -->
<!-- Encrypt DB, get KeyStorePass from userid.i -->
<if>
<equals arg1="${env.DB_Encryption}" arg2="True" ></equals>
<then>
<echo>Encrypting database...</echo>
<PCTRun procedure="npui/Src/TDEEncryption.p" dlcHome="${env.DLC}" failOnError="true">
<Parameter name="DB_Path" value="${DB_To_Encrypt_Dir}"/>
<Parameter name="Proutil_Path" value="${env.DLC}/bin/_proutil"/>
<Parameter name="Bin_Folder" value="${env.DLC}/bin"/>
<Parameter name="DB_Area" value="TellerTableArea"/>
<propath refid="includes-propath"/>
</PCTRun>
<delete file="${DB_To_Encrypt_Dir}.lg" />
</then>
</if>
</target>
TDEEncryption.p program:
DEFINE VARIABLE lv-db-path AS CHARACTER NO-UNDO.
DEFINE VARIABLE lv-proutil-path AS CHARACTER NO-UNDO.
DEFINE VARIABLE lv-DB-Area AS CHARACTER NO-UNDO.
DEFINE VARIABLE lv-bin-folder AS CHARACTER NO-UNDO.
lv-db-path = DYNAMIC-FUNCTION('getParameter' IN SOURCE-PROCEDURE, INPUT 'DB_Path').
lv-proutil-path = DYNAMIC-FUNCTION('getParameter' IN SOURCE-PROCEDURE, INPUT 'Proutil_Path').
lv-DB-Area = DYNAMIC-FUNCTION('getParameter' IN SOURCE-PROCEDURE, INPUT 'DB_Area').
lv-bin-folder = DYNAMIC-FUNCTION('getParameter' IN SOURCE-PROCEDURE, INPUT 'Bin_Folder').
lv-db-path = QUOTER(lv-db-path).
lv-proutil-path = "/C " + "set PATH=" + lv-bin-folder + ";%PATH% " + " & " + lv-proutil-path.
RUN processEncryption(1, lv-proutil-path + " " + lv-db-path + " -C enableencryption -Passphrase").
RUN processEncryption(2, lv-proutil-path + " " + lv-db-path + " -C epolicy manage area encrypt " + lv-DB-Area + " -Passphrase").
RUN processEncryption(3, lv-proutil-path + " " + lv-db-path + " -C epolicy manage area update " + lv-DB-Area + " -Passphrase").
PROCEDURE processEncryption:
DEFINE INPUT PARAMETER ipi-Type AS INTEGER NO-UNDO.
DEFINE INPUT PARAMETER ipc-Arguments AS CHARACTER NO-UNDO.
DEFINE VARIABLE procinfo AS ProcessStartInfo NO-UNDO.
DEFINE VARIABLE proc AS Process NO-UNDO.
DEFINE VARIABLE mystreamwriter AS StreamWriter NO-UNDO.
procinfo = NEW ProcessStartInfo().
proc = NEW Process().
procinfo:FileName = "cmd.exe".
procinfo:UseShellExecute = FALSE.
procinfo:RedirectStandardOutput = FALSE.
procinfo:RedirectStandardInput = TRUE.
procinfo:Arguments = ipc-Arguments.
proc:StartInfo = procinfo.
proc:Start().
mystreamwriter = proc:StandardInput.
mystreamwriter:WriteLine({&DataAtRest}).
IF ipi-Type = 1 THEN
DO:
mystreamwriter:WriteLine({&DataAtRest}).
mystreamwriter:WriteLine({&DataAtRest2}).
mystreamwriter:WriteLine({&DataAtRest2}).
END.
mystreamwriter:Dispose().
mystreamwriter:Close().
proc:WaitForExit().
END PROCEDURE.
RETURN.
We are using System.Diagnostics to run proutil commands inorder to encrypt our db. Currently if any error occurs with above proutil commands it is not failing build. It shows the error in logs but in the end it says build successful.
Do we have any ways to fail build here if my TDE encryption fails?
You should be able to query proc:Exitcode after the WaitForExit().
Exitcode 0 means a successful run, you should you should throw your error condition if it returns non-zero.
proutil should exit with a non-zero exit code when something goes wrong. If it doesn't, report that as a defect to Tech Support.
You should be able to query proc:Exitcode after the WaitForExit().
Exitcode 0 means a successful run, you should you should throw your error condition if it returns non-zero.
proutil should exit with a non-zero exit code when something goes wrong. If it doesn't, report that as a defect to Tech Support.
Thanks..Its works like a charm. :)