Scripts¶
The scripts
service allows writing and running the business logic of an application.
To see the ‘Scripts’ menu entry on P6 Portal, the scripts=view
permission is required.
For a summary of permission names and uses related to this service, please refer to this section.
Note
If you have the scripts=*
permission, you can have access to all the functions mentioned below.
List and view the Scripts¶
To list and view all the Scripts, the scripts=read
permission is required.
If your permission has values like this: scripts=read('Script 1', 'Script 2')
, you will only see the Script 1 and Script 2 Scripts.
Warning
With the scripts=read
permission, you will not be able to edit the resources.
You can view the resources of a script by double-clicking on the related line on the table displaying the results.
On the left, you have the list of resources and on the right the code editor.
A resource consists of a name, a type (Groovy, XML, HTML, XSLT, TEXT, TypeScript) and a content. By clicking on a resource’s name, you display the content in the code editor.
Run a Script¶
To run a Script, you need to have the scripts=read
and scripts=run
permissions.
You can run a script from the code editor’s tab. You will have at your disposal three buttons on the top right of the code editor to manage the script running.
Warning
You can only run a script if all your modifications on the resources have been saved.
Display logs¶
The ‘Display logs’ button allows displaying or hiding the console below the code editor. This console shows the logs during the script execution. It automatically opens at the start of the execution.
Add pipeline variables¶
The ‘Add pipeline variables’ button displays a modal view to add or remove execution pipeline variables. Pipeline variables are not required and consist of a key (which cannot be empty) and a value. You can run your script from this modal view.
Run and stop a Script¶
The ‘Run’ button starts the execution of the script with any entered pipeline variables. Once started, the logs will be displayed in the shell, but you can halt the execution with the ‘Stop’ button.
Run Tests¶
The Run test(s)
button appears only when you have groovy resources with the _test
suffix. It will run tests written inside the _test
resources.
Edit a Script¶
To edit scripts, you need to have the following permissions: scripts=read
and scripts=edit
.
When a script is created, it will create by default a Groovy resource, named main
. It will be your entry point when running the script.
Tip
Please read:
- the Groovy guide section to take advantage of the plugins added to Platform 6 Groovy interpreter
- the Scripts libraries section to learn how to share resources between scripts
You can access to the code editor by double-clicking on a script in the grid and with the scripts=edit
permission, you will be able to save your changes.
Edit its name and description¶
To update a script‘s name and description, click on ‘Edit details’ orange button located on the top right part of the tab.
Warning
The script‘s name and an English description are mandatory and cannot be empty.
You can get back to the edition of resources thanks to the ‘Edit resources’ orange button.
Edit its resources¶
Back on the main ‘Edit’ tab, you can manage the script‘s resources:
- Create a new resource
- Rename a resource
- Duplicate a resource
- Delete a resource
None of the actions above is available for the ‘main’ resource.
Tip
You can use the keyboard shortcut Ctrl + s
/Cmd + s
to save your changes in the code editor.
Create¶
Adding a new resource will open a new tab with a form. You will be asked to choose a unique name and to select a type for your new resource.
Rename¶
To rename a resource, you need to double-click on the resource’s name in the list. An input will be displayed and you will be able to choose a new name.
To validate the new name, press ‘Enter’, otherwise click anywhere else. As for the script‘s name, you will get a notification if the resource’s name is already taken.
Duplicate¶
To duplicate a resource, click on the resource’s name and hit the ‘Duplicate’ button. A new resource based on the initial resource will directly be created. Only, the name will be indexed.
Delete¶
To delete a resource, click on the resource’s name and hit the ‘Delete’ button. You will be asked to confirm the deleting.