R.V
R.V

Reputation: 239

Passing arguments from a file to shell in Pipeline

Basically I'm trying to pass properties to shell from a file.

I have a file "docker_info" with following content in workspace

IMAGE_NAME='Docker-image'

IMAGE_VERIONS='Docker-1.3.5'

Here is my pipeline script:

node
{

load "${WORKSPACE}/docker_info"

sh " echo ${IMAGE_NAME}" // here getting expected output: Docker-image

stage('Executing SHELL SCRIPING TO CHECK DOCKER IMAGE')

        sh '''

         echo "$DOCKER_IMAGE"

            if [ -z "${IMAGE_NAME}" ]     //(also tried "$IMAGE_NAME")
            then
            echo "Docker image not found."
            exit 0
            fi

             echo "${IMAGE_NAME}:started pushing image"

         '''   
}

OUTPUT:

[Test_BUILD_PIPELINE] Running shell script

+ echo Docker-image

Docker-image     

**Entering stage Executing SHELL SCRIPTING TO CHECK DOCKER IMAGE**

Proceeding

[Pipeline] sh

[Test_BUILD_PIPELINE] Running shell script

+  echo ''
+ '[' -z '' ']'

+ echo 'Docker image not found. Skip pushing Docker image'

Docker image not found. Skip pushing Docker image

+ exit 0

Kindly note after entering into the stage I Won't see the expected value(Docker-image)instead displaying: echo ' '

I tried with several ways but that haven't worked.

Upvotes: 0

Views: 700

Answers (2)

R.V
R.V

Reputation: 239

sh '''

. /path/to/the/docker_info

if [ -z "$IMAGE_NAME" ]

then

echo "Docker image not found"

exit 0

fi

echo "$IMAGE_NAME:started pushing image"

'''

Upvotes: 1

glenn jackman
glenn jackman

Reputation: 246744

Try

    sh """

     echo '$DOCKER_IMAGE'

        if [ -z '$IMAGE_NAME' ]  
        then
        echo 'Docker image not found.'
        exit 0
        fi

         echo '$IMAGE_NAME:started pushing image' 

     """

Upvotes: 0

Related Questions