Custom Command and Custom Util
SINCE VERSION 9.0
What is a Custom Command and Custom Util?
You can add your own custom commands or custom utils to PIPEFORCE in a few steps.
After this you can use them inside your pipeline similar to the built-in commands and utils.
It is also possible to shadow any of the built-in commands and utils so you can change behaviour or mock certain parts for development or testing for example.
This can can be done by creating script in your app.
Custom Command with Python
Since Version 9.0
Once this function has been auto-deployed, you can call it similar to a command from inside any pipeline or using the Command API.
The function name will become the command name and the parameters will become the arguments to the function. For example, lets assume a function like this, which is deployed in an app with name io.pipeforce.myapp
:
def myfunction(text):
return "HELLO: " + text
And a pipeline which calls this function:
pipeline:
- io.pipeforce.myapp:myscript:myfunction:
text: "World!"
This example will execute the function myfunction(text)
on the script myscript
inside the app io.pipeforce.myapp
. The result will then be returned to the pipeline body and can be processed by subsequent commands as usual. The final output of the pipeline in this example would be:
HELLO: World!
For more information about how to create functions and execute them, see Python Functions .
Custom Command with Groovy
Since version 10
Admin Approval Required
Since a Groovy script can also access sensitive data, it must be approved by the admin of your instance on any QA and PROD instance before usage. On DEV instances, no approval is required.
In order to get approval, go to the LOGABIT Help Desk and create a request for approval for a given set of scripts. Note: This step has to be repeated in case the script code has changed.
You can also create a custom command using the Groovy Scripting Language.
Go to the Developer Workbench in the Portal and use the Custom Command wizard or create a property inside global/app/<appName>/command/<commandName>
with type text/x-groovy
.
Inside the Groovy Script you will have access to all default variables and args as described here: https://logabit.atlassian.net/wiki/spaces/PA/pages/2603319334.
After this you can call your custom command from inside your app pipelines using its name <commandName>
.
For example lets assume a Groovy Script located at global/app/io.pipeforce.myapp/command/hello.world
:
This script can then be referred to as a custom command by its name:
After execution, the body will contain this:
NOTE
The custom command will have precedence over the original one in case they have the same command name.
This approach can also be used to mock / override existing commands in case a command with this name already exists.
The custom command can be called only from pipelines inside the same app.
Custom Util with Groovy
SINCE VERSION 10
Currently it is not possible to create custom utils with Python. For these you have to implement a Groovy script instead.
Pipeline Utils can be used inside a Pipeline Expression in order to do some extra calculation or tasks. There are many built-in utils available. See here: Utils Reference.
In order to create your own custom util, you have to simply do this:
Create a Groovy script with a method of name function
in it at property store path global/app/io.pipeforce.myapp/util/<utilName>.<utilFunction>
and with type set to text/x-groovy
. After this, you can use it inside a Pipeline Expression using @<utilName>.<utilFunction>()
.
Lets see for example this Groovy script:
… which is stored at path:
… can then be used in a persisted pipeline this way:
… which will generate this output in the body:
You can also overload this util with multiple functions with different arguments: