Would be nice to ue parameters in defining pipelineName for dependencies

Comments

3 comments

  • Avatar
    Sharanya Bathey

    Hi Lee,

     

    You can already do something like this in Go.  

    Following is the snippet of config XML that does this.  It has been defined for the scenario - The pipeline template named "Build" publishes an artifact called "some.file". The pipeline template named "Deploy" fetches the artifact using a pipeline parameter called "#{UPSTREAM}". Once these templates are setup, pipeline D1 sets the parameter "UPSTREAM" to "B1", telling Go that the fetch artifact task needs to use B1 for fetching the artifact. It also adds a dependency on pipeline B1 so that this is valid.


    ========================================================= 
    <pipelines group="first"> 
    <pipeline name="B1" template="Build"> 
    <materials> 
    <git url="/tmp/git" /> 
    </materials> 
    </pipeline> 
    <pipeline name="D1" template="Deploy"> 
    <params> 
    <param name="UPSTREAM">B1</param> 
    </params> 
    <materials> 
    <pipeline pipelineName="B1" stageName="defaultStage" /> 
    </materials> 
    </pipeline> 
    </pipelines>

    <templates> 
    <pipeline name="Build"> 
    <stage name="defaultStage"> 
    <jobs> 
    <job name="defaultJob"> 
    <tasks> 
    <exec command="/bin/bash"> 
    <arg>-c</arg> 
    <arg>ls &gt;some.file</arg> 
    <runif status="passed" /> 
    </exec> 
    </tasks> 
    <artifacts> 
    <artifact src="some.file" dest="some.file" /> 
    </artifacts> 
    </job> 
    </jobs> 
    </stage> 
    </pipeline> 
    <pipeline name="Deploy"> 
    <stage name="defaultStage"> 
    <jobs> 
    <job name="defaultJob"> 
    <tasks> 
    <fetchartifact pipeline="#{UPSTREAM}" stage="defaultStage" job="defaultJob" srcfile="some.file" dest="my.file"> 
    <runif status="passed" /> 
    </fetchartifact> 
    </tasks> 
    </job> 
    </jobs> 
    </stage> 
    </pipeline> 
    </templates> 
    =========================================================

     

    Thanks,

    Sharanya

  • Avatar
    Sharanya Bathey

    Hi Lee,

    Sorry, please don't consider the above reply. 

     

    When you clone a pipeline in Go, the parameters for it are also cloned, with the same values. You could change the value of the parameter UPSTREAM for the newly cloned pipeline and it should take effect at all required places where the parameter is used

    So, if you have the following sample cruise-config.xml:

        <pipeline name="up42">
          <materials>
            <git url="/Users/sbathey/Desktop/gitREpo" materialName="gitRepo0" />
          </materials>
          <stage name="up42_stage">
            <jobs>
              <job name="up42_job">
                <tasks>
                  <exec command="ls" />
                  <exec command="echo">
                    <arg>"1234" &gt;&gt; 1.txt</arg>
                    <runif status="passed" />
                  </exec>
                </tasks>
                <artifacts>
                  <artifact src="1.txt" dest="pkg" />
                </artifacts>
              </job>
            </jobs>
          </stage>
        </pipeline>
        <pipeline name="sample">
          <params>
            <param name="UPSTREAM">up42</param>
          </params>
          <materials>
            <pipeline pipelineName="#{UPSTREAM}" stageName="up42_stage" />
          </materials>
          <stage name="defaultStage">
            <jobs>
              <job name="defaultJob">
                <tasks>
                  <fetchartifact pipeline="#{UPSTREAM}" stage="up42_stage" job="up42_job" srcfile="pkg/1.txt">
                    <runif status="passed" />
                  </fetchartifact>
                  <exec command="cat">
                    <arg>1.txt</arg>
                    <runif status="passed" />
                  </exec>
                </tasks>
              </job>
            </jobs>
          </stage>
        </pipeline>

    Now if you go ahead and clone the pipeline "sample" into sample2

    You would get the new pipeline sample2 with the parameter UPSTREAM as follows :

    <pipeline name="sample2">
          <params>
            <param name="UPSTREAM">up42</param>
          </params>
          <materials>
            <pipeline pipelineName="#{UPSTREAM}" stageName="up42_stage" />
          </materials>
          <stage name="defaultStage">
            <jobs>
              <job name="defaultJob">
                <tasks>
                  <fetchartifact pipeline="#{UPSTREAM}" stage="up42_stage" job="up42_job" srcfile="pkg/1.txt">
                    <runif status="passed" />
                  </fetchartifact>
                  <exec command="cat">
                    <arg>1.txt</arg>
                    <runif status="passed" />
                  </exec>
                </tasks>
              </job>
            </jobs>
          </stage>
        </pipeline>

     

    Please let me know if you have any other questions.

    Thanks,

    Sharanya

  • Avatar
    LeeBenhart

    This is just what I wanted to do, I did not think it was possible, I will work on this!

Please sign in to leave a comment.