0

Our shared library uses these two (slightly abstraced) calls. The first one works perfectly fine. The second one splits the ${UNITY_PATH} command into multiple lines split where spaces are.

A workaround is to exclude this command into a one-line-sh command - in case somebody else runs into this issue. But my question remains: Why is the `${UNITY_PATH} line split appart in the second scenario but not the first one? First Scenario (working case):


def call() {
    sh """
        rm -fr '${WORKSPACE}/${RELATIVE_TARGET_DIR_PRODUCTION}/TheWagaduChronicles.Production/Build/'
        ${UNITY_PATH} -batchmode -projectPath ./${RELATIVE_TARGET_DIR_PRODUCTION}/TheWagaduChronicles.Production -logfile - -executeMethod TheWagaduChronicles.Build.Editor.BuildMenu.BuildMacOSClient
        ${UNITY_PATH} -batchmode -projectPath ./${RELATIVE_TARGET_DIR_PRODUCTION}/TheWagaduChronicles.Production -logfile - -executeMethod TheWagaduChronicles.Build.Editor.BuildMenu.BuildWindowsClient
    """
}

Second scenario (failing case):

def call(String buildVersion) {
    sh """
        cd ${WORKSPACE}/${RELATIVE_TARGET_DIR_PRODUCTION}/.
        <more stuff happening>
        jq '.Version_ = ${buildVersion}' version.json | sponge version.json
        ${UNITY_PATH} -batchmode -projectPath ./$RELATIVE_TARGET_DIR_PRODUCTION/GreatProject.Production -logfile - -executeMethod GreatProject.Build.Editor.BuildMenu.SetBuildVersion
        git commit -m \"Bumps version to $buildVersion\"
        <more stuff happening>
        git push --tags --verbose
    """
}

Leads to:

11:40:54  COMMAND LINE ARGUMENTS:
11:40:54  /Applications/Unity/Hub/Editor/2021.3.12f1/Unity.app/Contents/MacOS/Unity
11:40:54  -batchmode
11:40:54  -projectPath
11:40:54  ./production/TheWagaduChronicles.Production
11:40:54  -logfile
11:40:54  -
11:40:54  -executeMethod
11:40:54  TheWagaduChronicles.Build.Editor.BuildMenu.SetBuildVersion
11:40:54  Couldn't set project path to: 
11:40:54  
11:40:54  Aborting batchmode due to failure:
11:40:54  Couldn't set project path to: 
11:40:54  

Workaround Hack:

def call(String buildVersion) {
    sh """
        cd ${WORKSPACE}/${RELATIVE_TARGET_DIR_PRODUCTION}/.
        <more stuff happening>
        jq '.Version_ = ${buildVersion}' version.json | sponge version.json
    """
    
    sh "${UNITY_PATH} -batchmode -projectPath ./$RELATIVE_TARGET_DIR_PRODUCTION/GreatProject.Production -logfile - -executeMethod GreatProject.Build.Editor.BuildMenu.SetBuildVersion"

    sh """
        git commit -m \"Bumps version to $buildVersion\"
        <more stuff happening>
        git push --tags --verbose
    """
}

Researched and troubleshooted until I found the hack included in the question. But I couldn't find an explanation.

vik
  • 164
  • 1
  • 10
  • Where is `UNITY_PATH` defined? – Matthew Schuchard Jan 05 '23 at 12:25
  • In the Jenkins pipeline (environment block) that is calling these functions. The variable if defined only once and used afterwards in both scenarios. – vik Jan 05 '23 at 14:06
  • I wonder if the leading spaces is the issue. If you run ```sh " ${UNITY_PATH} -batchmode -projectPath ./$RELATIVE_TARGET_DIR_PRODUCTION/GreatProject.Production -logfile - -executeMethod GreatProject.Build.Editor.BuildMenu.SetBuildVersion"``` does the command appear properly? – Vasiliki Siakka Jan 05 '23 at 16:29
  • Just tested it - and `sh " ${UNITY_PATH} -bat....` runs fine. – vik Jan 05 '23 at 21:08

1 Answers1

0

It might be related to the "strange" way Jenkins handles pipe subshells; see something like this stackoverflow post to get an idea of the weirdness. So my guess would be that actually jq '.Version_ = ${buildVersion}' version.json | sponge version.json throws off the following flow / commands. It might be worth a test?

Sir.Chefcoq
  • 330
  • 1
  • 7