How to clone a template

882 views
Skip to first unread message

Marius Ciotlos

unread,
Aug 12, 2014, 4:34:33 PM8/12/14
to go...@googlegroups.com
Hi guys, 

I wanted to write this topic for those interested in Cloning a template. There is a ruby script that you can find here: https://github.com/oanastoia/go-config-management that exposes this functionality in a way that is really easy to create a nice workflow around it. Credits for the script go to Oana Stoia which is the script owner. 
 
How we've used it:
  • Create a new Pipeline that will have a stage with a job with a task that will contain this script
Example:
<pipeline name="GoCloneTemplate">
  <environmentvariables>
    <variable name="SOURCE_TEMPLATE">
      <value>Source_Template</value>
    </variable>
    <variable name="DESTINATION_TEMPLATE">
      <value>Example_Clone</value>
    </variable>
    <variable name="API_PASS" secure="true">
      <encryptedValue>[your_encripted_pass]</encryptedValue>
    </variable>
    <variable name="API_USER" secure="true">
      <encryptedValue>[your_encripted_user]</encryptedValue>
    </variable>
  </environmentvariables>
  <materials>
  </materials>
  <stage name="CloneTemplate">
    <approval type="manual" />
    <jobs>
      <job name="clone_template">
        <tasks>
          <exec command="ruby">
            <arg>TemplateClone.rb</arg>
            <arg>clone</arg>
            <runif status="passed" />
          </exec>
        </tasks>
      </job>
    </jobs>
  </stage>
</pipeline>
  • Set the repo as material for your pipeline (as seen above)
  • Make sure that on your pipeline you have correctly set in the secure environment variables, a user that is a Go System Admin so it can use the api to save a config.xml back to the server
How will this look?





Cheers,
Marius

Ken Mugrage

unread,
Aug 12, 2014, 4:49:20 PM8/12/14
to Marius Ciotlos, go...@googlegroups.com

Cool info, thanks Marius.

Please consider submitting a pull request to the go.cd blog space for this info. You can fork the website from https://github.com/gocd/gocd.github.io. All you would need to do then is create a file in _posts following the same naming format and front-matter that's already there.

Thanks again,
Ken


--
You received this message because you are subscribed to the Google Groups "go-cd" group.
To unsubscribe from this group and stop receiving emails from it, send an email to go-cd+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Ken Mugrage - ThoughtWorks Studios OSS Program Manager
Twitter
@kmugrage

Marius Ciotlos

unread,
Aug 13, 2014, 5:01:01 PM8/13/14
to go...@googlegroups.com, cio...@gmail.com
Will do, thanks. 

Marius Ciotlos

unread,
Aug 19, 2014, 5:19:57 AM8/19/14
to go...@googlegroups.com, cio...@gmail.com
I've submitted a Pull Request

Marius Ciotlos

unread,
Aug 19, 2014, 6:47:56 AM8/19/14
to go...@googlegroups.com, cio...@gmail.com
This topic is now available on the blog here: http://www.go.cd/2014/08/19/cloning-templates.html

Jason D

unread,
Aug 19, 2014, 11:41:07 AM8/19/14
to go...@googlegroups.com
Sorry for being a bit late to the discussion. 
 
I'm confused as to how this is easier than just going into the config and copying the template xml.  The only thing easier than that would be to add a simple button in the UI to do so (same workflow as cloning pipeline).  Am I missing something here?

Marius Ciotlos

unread,
Aug 19, 2014, 3:54:32 PM8/19/14
to go...@googlegroups.com
Imagine you have in the config XML around 3k lines and the template you want to clone is complex enough to have 10 stages with around 3 jobs each with 1-2 tasks per job. The way most people do it is copy the XML out of GO, edit in a different tool and paste it back in. 
You have to know XML, it's prone to error and when you have to do this more than once it's not the best way. 

The workflow specified here allows you to setup this cloning pipeline once, and then just use it. You enter source and destination name and trigger it and you get the clone automatically done without having to interact with text editors and copy / pasting.
If it doesn't work for you it's fine, but many people found this more useful than editing inline xml.

Of course I would also find having a Clone button directly in the UI just like for pipelines the best, but someone has to implement that and the feature has to make it out into a release and then you have to upgrade your server which might not be in the near future. 

The solution presented here is a temporary solution until such functionality makes it inside GO. 


Marius
Reply all
Reply to author
Forward
0 new messages