jenkinsgroovypipelinecshtcsh

Jenkins Pipeline Groovy script tcsh alias expansion


I have a legacy project in Jenkins that hast to be pipelined (for later parallelization), hence moving from simple tcsh script to pipeline

running the script as

#!/bin/tcsh
source ./mysetting.sh
update

works but the same pipeline step fails due to missing alias expansion

stage ('update') {
    steps {
        //should be working but alias expansion fails
        sh 'tcsh -c "source ./mysettings.sh; alias; update"' 
           
        //manually expanding the alias works fine
        sh 'tcsh -c "source ./mysettings.sh; alias; python update.py;"' 
        }
}

calling alias in the steps properly lists all the set aliases, so I can see them, but not use them.

I know in bash alias expansion has to be set

#enable shell option for alias_expansion
shopt -s expand_aliases

but in csh/tcsh that should be taken care of by source.

what am I missing?


Solution

  • found the solution:

    sh  '#!/bin/tcsh \n' +
        'source ./mysettings.sh \n' +
        'echo "Calling my alias" \n' +
        'my_alias \n'
    

    every line starting with sh launches a new shell, so it has to be in one line including line breaks.

    further adding to the confusing was that documentation of jenkins says that it starts "a bash" but it launched /bin/sh which in my case pointed to something else