0

I am running into an error I don't quite understand. My windows and Batch are probably my worst so be gentle. I inherited this mess and I am trying to figure it out. I initially thought it was just a permissions error, as the team I took this from was passing the creds from jenkins into plain text file then into mpiexec. Yes I know... Now I am testing with just the creds in plain text to make sure its actually works period, then I will handle the proper solution. I have removed sensitive information from the code and log file.

I have made one change to this code so far, and that was removing the plain text file and just passing in the creds directly into mpiexec as you will see below. First is the log output, then the code.

ccr\******* c:\iusers\jenkins\workspace\impi_PR-3056_qy6gczv2>mpiexec -register -username CCR\****** -password **** 

[2022-09-22T18:39:50.318Z] credentials were saved.

[2022-09-22T18:39:50.318Z] ) was unexpected at this time.

[2022-09-22T18:39:50.318Z] ccr\********c:\iusers\jenkins\workspace\impi_PR-3056_qy6gczv2>) else if /i "ONEAPI" equ "PSXE" (

script returned exit code 255

package impi

import infra.util.*

public class Deploy {
    final private def script
    final private String artifactsDir
    final private def params
    final private String siteId

    public Deploy(final def script, final String artifactsDir, final def params, final String siteId) {
        this.script = script
        this.artifactsDir = artifactsDir
        this.params = params
        this.siteId = siteId
    }

    public void deployLinux() {
        script.withEnv([
            "PACKAGE_INSTALL_LAYOUT=${params.PACKAGE_INSTALL_LAYOUT ?: 'ONEAPI'}",
            "artifacts_dir=${artifactsDir}",
            "ONEAPI_GLOB=${Consts.OS_CUSTOMIZED_VARS.linux.oneapiPackageMask}",
            "PSXE_GLOB=${Consts.OS_CUSTOMIZED_VARS.linux.psxePackageMask}"
        ]) {
            script.sh('''#!/bin/bash
                set -ex -o pipefail
                # Package specifications
                ONEAPI_DIR_NAME="oneapi_impi"
                PSXE_DIR_NAME="psxe_impi"
                ###
                PACKAGE_INSTALL_LAYOUT=${PACKAGE_INSTALL_LAYOUT:-ONEAPI}
                echo "DEBUG: Install package for ${PACKAGE_INSTALL_LAYOUT} configuration"
                selector_glob="${PACKAGE_INSTALL_LAYOUT}_GLOB"
                selector_dirname="${PACKAGE_INSTALL_LAYOUT}_DIR_NAME"
                package_path=$( ls -1 $artifacts_dir/${!selector_glob} )
                package_target_dir_name=${!selector_dirname}
                tar xfz $package_path
                pushd $( basename $package_path .tgz ) > /dev/null
                    unzip -P accept package.zip
                    ./install.sh -s -d $artifacts_dir/$package_target_dir_name
                    echo "DEBUG: Package in ${PACKAGE_INSTALL_LAYOUT} configuration successfully installed to $artifacts_dir/$package_target_dir_name dir"
                popd > /dev/null
                echo "DEBUG: Enable ${PACKAGE_INSTALL_LAYOUT} testing layout"
                ln -s $artifacts_dir/$package_target_dir_name $artifacts_dir/impi
            ''')
        }
    }

    public void deployWindows() {
        script.withEnv([
            "ARTIFACTS_DIR=${Utils.getWindowsPath(script, artifactsDir, "^/p/", BaseConsts.CIFS_SERVER_v0[siteId])}", // Autogen archive is always here
            """MPI_ARCHIVE_PATH=${params.MPI_ARCHIVE_PATH ?
                Utils.getWindowsPath(script, params.MPI_ARCHIVE_PATH, "^/p/", BaseConsts.CIFS_SERVER_v0[siteId]) :
                Utils.getWindowsPath(script, artifactsDir, '^/p/', BaseConsts.CIFS_SERVER_v0[siteId])}""",
            "PSXE_PACKAGE_MASK=${Consts.OS_CUSTOMIZED_VARS.windows.psxePackageMask}",
            "ONEAPI_PACKAGE_MASK=${Consts.OS_CUSTOMIZED_VARS.windows.oneapiPackageMask}",
            "TOOLS_DIR=${Utils.getWindowsPath(script, BaseConsts.CIFS_TOOLS_DIR_v0, "^/p/", BaseConsts.CIFS_SERVER_v0[siteId])}",
            "CYGWIN_DIR=${BaseConsts.CYGWIN_DIR}",
            "SRC_DIR=${Consts.WINDOWS_SRC_DIR}",
            "PACKAGE_INSTALL_LAYOUT=${params.PACKAGE_INSTALL_LAYOUT ?: 'ONEAPI'}"
        ]) {
            script.withCredentials([script.usernamePassword(credentialsId: 'ec25177f-b239-43cb-a2d5-874a88f97fc9', passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')]) {
              script.bat('''
                   PATH=%TOOLS_DIR%\\unzip-5.51-1-bin\\bin;%CYGWIN_DIR%\\bin;%PATH%
                   REM Create a source dir in local workspace
                   if exist %SRC_DIR% rmdir /s/q %SRC_DIR%
                   if %errorlevel% neq 0 exit /b %errorlevel%
                   mkdir %SRC_DIR%
                   REM Obtain IMPI sources with autogen results
                   copy %MPI_ARCHIVE_PATH%\\impi_src.tgz .
                   copy %ARTIFACTS_DIR%\\workspace-1-autogen.tgz .
                   tar -xzf impi_src.tgz -C %SRC_DIR%
                   if %errorlevel% neq 0 exit /b %errorlevel%
                   tar -xzf workspace-1-autogen.tgz -C %SRC_DIR%
                   icacls %SRC_DIR% /remove sys_ctlab
                   icacls %SRC_DIR% /Q /grant sys_ctlab:(OI)(CI)F /T
                   icacls %SRC_DIR%
                   echo "INFO: Deploy %PACKAGE_INSTALL_LAYOUT% package layout"
                   REM (echo CCR\\%USERNAME%& echo %PASSWORD%& echo %PASSWORD%) > auth_data.txt
                   mpiexec -register -username CCR\\****** -password ****

                   REM Obtain IMPI packages and configure services
                   if /i "%PACKAGE_INSTALL_LAYOUT%" equ "ONEAPI" (
                       copy %MPI_ARCHIVE_PATH%\\%ONEAPI_PACKAGE_MASK% .
                       unzip -o -P"accept" %ONEAPI_PACKAGE_MASK%
                       if %errorlevel% neq 0 exit /b %errorlevel%
                       bin\\hydra_service.exe -install
                       if %errorlevel% neq 0 exit /b %errorlevel%
                       env\\vars.bat
                       if %errorlevel% neq 0 exit /b %errorlevel%
                       REM TODO: Fix the mpiexec register call w/ credentials
                       REM type auth_data.txt | mpiexec -register
                       REM if %errorlevel% neq 0 exit /b %errorlevel%
                   ) else if /i "%PACKAGE_INSTALL_LAYOUT%" equ "PSXE" (
                       copy %MPI_ARCHIVE_PATH%\\%PSXE_PACKAGE_MASK% .
                       unzip -o -P"accept" %PSXE_PACKAGE_MASK%
                       if %errorlevel% neq 0 exit /b %errorlevel%
                       intel64\\bin\\hydra_service.exe -install
                       if %errorlevel% neq 0 exit /b %errorlevel%
                       intel64\\bin\\mpivars.bat
                       if %errorlevel% neq 0 exit /b %errorlevel%
                       REM TODO: Fix the mpiexec register call w/ credentials
                       REM type auth_data.txt | mpiexec -register
                       REM if %errorlevel% neq 0 exit /b %errorlevel%
                   ) else (
                       echo "ERROR: PACKAGE_INSTALL_LAYOUT=%PACKAGE_INSTALL_LAYOUT% is not correct! Please use PSXE or ONEAPI."
                       exit /b 1
                   )
                   del auth_data.txt
                '''.stripIndent())
            }
        }
    }

    public void uninstallWindows() {
        script.withEnv([
            "PACKAGE_INSTALL_LAYOUT=${params.PACKAGE_INSTALL_LAYOUT ?: 'ONEAPI'}"
        ]) {
            script.bat('''
                if /i "%PACKAGE_INSTALL_LAYOUT%" equ "ONEAPI" (
                    if exist "bin\\hydra_service.exe" bin\\hydra_service.exe -remove
                    if %errorlevel% neq 0 exit /b %errorlevel%
                    rem rmdir /s /q "bin"
                    rem if %errorlevel% neq 0 exit /b %errorlevel%
                ) else if /i "%PACKAGE_INSTALL_LAYOUT%" equ "PSXE" (
                    if exist "intel64\\bin\\hydra_service.exe" intel64\\bin\\hydra_service.exe -remove
                    if %errorlevel% neq 0 exit /b  %errorlevel%
                    rem rmdir /s /q "intel64\\bin"
                    rem if %errorlevel% neq 0 exit /b %errorlevel%
                ) else (
                    echo "ERROR: PACKAGE_INSTALL_LAYOUT=%PACKAGE_INSTALL_LAYOUT% is not correct! Please use PSXE or ONEAPI."
                )
            '''.stripIndent())
        }
    }
}
Dvsmp
  • 1
  • 2
  • 1
    You have posted a code box which seems to include `ccr\*******`, with no explanation...Then random lines, ```script.bat('''``` and ```PATH=%TOOLS_DIR%\unzip-5.51-1-bin\bin;%CYGWIN_DIR%\bin;%PATH%a```, with no context or explanation. Then the code you have submitted below that is incomplete, it uses variables we have not seen defined, and each line is seemingly indented with at least fifteen single space characters, so that we cannot read it properly. How about you use the [edit] button, submit your corrected code, according to the comments, then try again, so we can all understand your issue. – Compo Sep 26 '22 at 16:00
  • @Compo I clearly stated I edited out sensitive information, The variables are not the issue, but I included everything now. I understand it looks like crap, but this is what was thrown in my lap and I am trying to figure it out the best I can. – Dvsmp Sep 26 '22 at 16:30
  • This is way different scenario now as the code you posted (after edit) shows java code with embedded bash/sh and cmd depending on the OS – Gerhard Sep 26 '22 at 17:21
  • I was thinking it wasn't necessary to show a huge wall, when everything is running as expected up to right after the mpiexec register part. Apologies. – Dvsmp Sep 26 '22 at 17:53
  • Within your `.bat` content there are several parenthesized blocks. When a block is parsed variables defined within them will be read before the code is run. That means you would need to delay the expansion of those variables, or perform the task in a different way. For example, `if %errorlevel% neq 0` or more correctly `if not "%errorlevel%" == "0"` should be, after enabling delayed expansion, using `!errorlevel!` instead of `%errorlevel%`. Alternatively, in most situations, not yours, you could change those to just `if errorlevel 1`, which doesn't involve the use of a variable within a block. – Compo Sep 26 '22 at 19:47

1 Answers1

0

Given the following section of code, which is where thing appear to be falling over: - I've added comments

  ) else if /i "%PACKAGE_INSTALL_LAYOUT%" equ "PSXE" (
   copy %MPI_ARCHIVE_PATH%\\%PSXE_PACKAGE_MASK% .
   unzip -o -P"accept" %PSXE_PACKAGE_MASK%

"%errorlevel%" will be replaced on execution by the value that errorlevel had at the time

REM (echo CCR\\%USERNAME%& echo %PASSWORD%& echo %PASSWORD%) > auth_data.txt
mpiexec -register -username CCR\\****** -password ****

was executed, not the result of the UNZIP. You need if errorlevel 1 here to react to the result of executing the UNZIP.

   if %errorlevel% neq 0 exit /b %errorlevel%
   intel64\\bin\\hydra_service.exe -install

Ditto, but hydra_service, not UNZIP

   if %errorlevel% neq 0 exit /b %errorlevel%

This should SWITCH to the .bat file. You'd need to CALL it to return here

   intel64\\bin\\mpivars.bat
   if %errorlevel% neq 0 exit /b %errorlevel%
   REM TODO: Fix the mpiexec register call w/ credentials
   REM type auth_data.txt | mpiexec -register
   REM if %errorlevel% neq 0 exit /b %errorlevel%

You can access the run-time value of errorlevel by using delayedexpansion - Stephan's DELAYEDEXPANSION link: https://stackoverflow.com/a/30284028/2128947

Magoo
  • 77,302
  • 8
  • 62
  • 84