Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member354304
Active Participant
Hey, I haven't blogged in a while, so I am happy to get back to one of my favorite hobbies - writing blog posts. Today I will introduce one of the brand new features we are having in SAP Automation Pilot - writing scripts within the Pilot.

Why is this important?


In our daily operations tasks, we try to automate almost everything. Why? Because it saves us time - there are many boring, repetitive tasks that we don't want to do manually, simply because computers are much better than us in this and automation allows us to concentrate on more important work in our backlog. One of the most common tools for this is scripting - having low-level scripting running on our operating systems allows us to achieve a lot in a relatively fast manner. However, it brings a lot of trouble with it - we have to maintain the code, run it, orchestrate the input and output, etc.

With Automation Pilot, you can delegate the execution and orchestration of your existing scripts to the service itself; even more, you can write your own scripts within the Automation Pilot's UI.

 

How?


To make it easier to explain, I will build an example from scratch - a simple script that restarts many Cloud Foundry-based microservices.

In Automation Pilot, I will create a command called RestartApps.


I will define three inputs - password, region, and user. I need the user and the password to authenticate before the Cloud Foundry and the region to point where my apps are.

I will also define two output keys -  the exitCode and output- to understand how my script was completed and potentially troubleshoot. Also, I can use them within other commands and, based on this output, to take decisions and orchestrate additional steps.


 

Now let's add a new command of type ExecuteScript, and give it the name "RestartApps."


Then select the newly created button, and let's write our script by hitting the Edit button.


 

Now it is time to write my script - I have chosen Bash as a scripting language. However, Automation Pilot supports also  - node.js, python, and Perl.

Firstly, I will map my input parameters (user, password, and region) to environment variables. I am going to click on the Environment button and add the user and the region within it.


Now it is time for the password. As it is a sensitive string, I don't want to keep it as a variable, so I will pass it via STDIN; I will click on the STDIN tab and add map my password parameter; I will also encode it with base64 as this is requested by the cf client.


Now it is time to write my script - which consists of simple CF CLI invocations which will restart my microservices.

Here's the script in a copy-paste format



#!/usr/bin/env bash

read -t 5 PASSWORD

cf api "${API}"
cf auth "${USER}" "${PASSWORD}"
cf target -o mycforg -s prod # replace 'mycforg' and 'prod' with your org and space

#replace the ones below with the apps you want to restart
cf restart backend &
cf restart app-backend-push &
cf restart app &
cf restart app-retriever &
cf restart app-retriever-backup

 

Lastly, I will configure acceptable exit codes and timeout (by default, the timeout is 30 seconds, I will give it a good 300 seconds).


Finally, when I hit the Update button, my command should look like this.


 

With this command now, I can restart all of the microservices, share the command with my colleagues, and include it in broader scenarios. And this is just a glimpse of the capabilities of Automation Pilot. Stay tuned for more blog posts.

 

What's next?


You can subscribe to SAP Automation Pilot and use it, then give us your feedback. We are constantly looking to improve the service.

You can also check out our upcoming OpenSAP course and learn more about Automation Pilot, SAP Alert Notification, and many other services which can help you setup your DevOps processes better.

Explore additional blog posts right here
4 Comments