Pass variables to other pipelines

Follow

Comments

4 comments

  • Avatar
    Jeff Vincent

    Could you elaborate on how to save the values fetched from the upstream/dependent pipeline so they can be used in the current one?

  • Avatar
    Sriram Narayan

    Rather than saving, could you do with fetch and use when needed? In the following examples, I fetch and pass the property as an argument to myscript.sh (regular material)

    <exec command="/bin/bash" >
      <arg>-c</arg>
      <arg>path/to/myscript.sh `curl http://go-server:8153/go/properties/${GO_DEPENDENCY_LOCATOR_XX}/job-name/appversion 2>/dev/null|sed -n '2p'`</arg>
    </exec>

    OR

    <exec command="/bin/bash" >
      <arg>-c</arg>
      <arg>prop=$(curl http://go-server:8153/go/properties/${GO_DEPENDENCY_LOCATOR_XX}/job-name/appversion 2>/dev/null|sed -n '2p');/path/to/myscript.sh $prop</arg>
    </exec>
  • Avatar
    Jeff Vincent

    Except all this is very OS-specific based on where the Agent runs when there is nothing OS specific about what I am trying to do.

    Specifically, I am trying to change the profile that is used for my Maven command.  In one case, I want to run:

          mvn install -PlatestSnapshot

    and in the other case I want to run:

         mvn install -PlatestRelease

    In my custom command I prefer something like:

         mvn install -P${ARTIFACT_TYPE}

    But I can't set properties in the scheduler (that I have found).  So I set the property on the parent Pipeline thinking I could reference it from the downstream pipeline.  However, I don't think there is a way to save the result of the CURL command to a property for use elsewhere without OS-specific scripts.  Not to mention again that the CURL command is very OS-specific anyway.

    In an attempt to use environment variables, I've tried:

         mvn install -P%ARTIFACT_TYPE%

    and then passing the environment variable in via the REST call to schedule the job.  But it only works on Windows due to the %%.  If I make it Linux-specific and do:

         mvn install -P$ARTIFACT_TYPE

    it doesn't work at all because $ARTIFACT_TYPE is not evaluated properly on Linux, and even if it did, it is still OS-specific.

    Is there not a way to pass in a property when scheduling a job that can be set and used as any other property without writing OS-specific scripts?

  • Avatar
    Sriram Narayan

    Hmm. I'm afraid it is OS specific when it comes to dereferencing an environment variable. The only other way I can think of is to use parameters but they are statically bound so I'm not sure if it will serve your purpose. Do take a look at : http://support.thoughtworks.com/entries/23694116-Parameters-and-Environment-Variables

    >$ARTIFACT_TYPE is not evaluated properly on Linux

    Can you try with ${ARTIFACT_TYPE} 

Please sign in to leave a comment.