1

Here is my script. Im trying to set up variables in pipline shell script:

node {


  anyconnect = docker.image('anyconnect:1').run("--cap-add NET_ADMIN --cap-add SYS_ADMIN --device /dev/net/tun:/dev/net/tun -e VPN_USER=${env.USER} -e VPN_PASS=${env.PASS} --name anyconnect")

  sh 'echo "Startig anyconnect and setting route"'

  sh """
    IPADDRESS = \$(docker inspect -f "{{ .NetworkSettings.IPAddress }}" anyconnect)
    echo $IPADDRESS
    ip route replace xx.xx.xx.xx. via $IPADDRESS
    """



  anyconnect.stop()



}

But im getting:

groovy.lang.MissingPropertyException: No such property: IPADDRESS for class: groovy.lang.Binding

I was trying to export it and other things like useing ${env.VARIABLE} or just ${VARIABLE} still not helping to set up variable in pipeline. How it should be done with Jenkins pipelines?

user3069488
  • 159
  • 2
  • 3
  • 18

1 Answers1

3

Replace your double quotes with single quotes to prevent $IPADDRESS from being interpreted as a Groovy variable:

  sh '''
    IPADDRESS = \$(docker inspect -f "{{ .NetworkSettings.IPAddress }}" anyconnect)
    echo $IPADDRESS
    ip route replace xx.xx.xx.xx. via $IPADDRESS
    '''

Alternatively, escape the dollar sign:

  sh """
    IPADDRESS = \$(docker inspect -f "{{ .NetworkSettings.IPAddress }}" anyconnect)
    echo ${'$'}IPADDRESS
    ip route replace xx.xx.xx.xx. via ${'$'}IPADDRESS
    """
jayhendren
  • 917
  • 4
  • 11