Script sharing

Hello

It it possible to store and reuse a script (SSH/CMD) in the Teamcity?
There is 2 build configurations and similar scripts. It would be efficient to store the script outside of build steps and use it with variables specific for each step. 

Thanks in advance.
 

0
10 comments

Isn't this what Templates are used for?   You can create a template from your current "build A” using Actions, Extract Template, move what you need to parameters, and then create a "build B" from that template and override what you need.

We use this alot, and try hard to minimize the overriding of build steps, as we want everything built exactly the same, the only thing we override are parameters.

0

I'm using the Templates. Do you have duplicate steps in different templates?
I have. For example I've 2 templates - “Deploy Linux Ubuntu”, “Deploy Linux Debian”. It is different, because need different steps. But few steps are the same and I don't want to duplicate it and support similar steps in different templates.

Also there is a bug probably in the SSH step. If you have an SSH step in a template - it's not working good. Because you need to select different SSH keys in build configuration. And selection of SSH key overrides the step. Step is no longer linked to template, so SSH script in template do not affect to the build configuration.

0

Yes, you can use a common template and delete the steps that aren't required and add new steps that are, or better still try and make the template steps generic using parameters, so they are general deployment steps using a parameter for deployment push path for example.

0

Different templates has different steps and it order. That would not work good via templates.

0

If they are more dissimilar than they are similar, templates are not a good fit. Perhaps Meta Runners?  Not used them myself, but might be what you are looking for?

https://www.jetbrains.com/help/teamcity/2024.07/working-with-meta-runner.html?Working+with+Meta-Runner

0

Thanks Mark, I'll try this. 

Do you know, is it possible to store executable file in the TC, a tool? To use in meta runner or template later. 

0

Yes, we have quite a few of our own tools that we have created as plugin tools, essentially commandline tools that execute on the build agent,.

Installing Agent Tools | TeamCity On-Premises Documentation

They are just zip files with an tool descriptor XML

Plugins Packaging | TeamCity Plugin Development Help Documentation

Once uploaded to the server, you can then access via scripts using %teamcity.tool.mytoolname%

 

 

 

1
 Hi Kinguru2006,

Do you still have any issues regarding this matter?

If so, please feel free to add them there.

Best Regards,
Tom
0

Hi everybody, 

I keep in mind proposed variant of script sharing but have no chance to try it in my build flow. I hope to try this during next month, so currently no questions I have. 

I wish you Merry Christmas and happy new year!

0

I have an update on this.  We needed to create a powershell signing script (using the azuresigntool), and this gave me the opportunity to try out metarunners.

 

I created a build task, our powershell signing script, and then exported it as a metarunner to the root project.   This script can then be used in all projects as a build step, with any parameters needed passed in wherever they need to be used.

Think of them as build step templates, rather than build plan templates.

 

1

Please sign in to leave a comment.