There are 3 ways to supply argument to Cloud app

  1. Command Line during app startup
  2. using gradle.build
  3. manifest.yml

How to supply Argument to Spring Controller during application startup in Gradle Wrapper

gradlew bootRun --args='--welcome.message=Mugil'

WelcomeController.java
In the below code welcomeMsg variable is assigned value during application startup. In similar ways environment variables could be setup
by supplying arguments as parameters while executing gradlew bootrun

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class WelcomeController {
    public String welcomeMsg;

    @Autowired
    public WelcomeController(@Value("${welcome.message}") String message) {
        welcomeMsg = message;
    }

    @GetMapping("/")
    public String sayHello() {
        return welcomeMsg;
    }
}

How to supply Argument to Spring Controller using gradle.build
build.gradle

.
.
.
bootRun.environment([
        "WELCOME_MESSAGE": "A welcome message",
])

test.environment([
        "WELCOME_MESSAGE": "Hello from test"
])

supply Arguments using manifest.yml
(works only in cloud env since manifest.yml is way of supplying argument from app to cloud env)

---
applications:
  - name: pal-tracker
    path: build/libs/pal-tracker.jar
    random-route: true
    env:
      WELCOME_MESSAGE: Hello from Cloud Foundry
      JBP_CONFIG_OPEN_JDK_JRE: '{ jre: { version: 11.+ } }'

Cloud Foundry Command Line Interface (cf CLI) is your primary tool for deploying and managing your applications and tasks.

Following are the Steps in Deploying Pivotal App

  1. Clone the App
    git clone https://github.com/cloudfoundry-samples/cf-sample-app-rails.git
    
  2. Log in and Target the API Endpoint

    cf login -a YOUR-API-ENDPOINT
    
  3. Create a Service Instance

    cf create-service SERVICE_NAME
    
  4. Creating a Route
    Before deploying an app we need a route(API url) which tells where the app would be deployed.Now when creating a route, you need a route which may or may not available. You can opt for random route as below if the route is not available during time of push

    Custom Route

    cf create-route SPACE_NAME DOMAIN_NAME DESIRED_ROUTE_NAME 
    cf create-route cloudnative cfapps.io pal-tracker.cfapps.io
    

    Random Route

    cf push APP_NAME -p APP_LOCATION/APP_NAME.jar --random-route
    
  5. Deploy the App
    cf push APP_NAME
    
  6. Bind the Service Instance
     cf bind-service APP_NAME SERVICE_NAME
    
  7. Verify the App – by browsing URL
     
    APP_NAME.cfapps.io
    
  8. A droplet is an archive within Cloud Foundry that contains the application ready to run on Diego. A droplet is the result of the application staging process.

    cf restage APP_NAME
    
  9. Use cf restage to refresh the environment variables and cf services to get the list of services
    Viewing Recent Logs in CLI

    cf logs APP_NAME --recent
    
  10. Viewing List of Environment Variables Available

    cf env APP_NAME
    
  11. Set environment from Command Prompt
    In the below example welcome.message is a variable created by user in gradle.build to be available at environment level.You can override it by supplying value in command prompt

    cf set-env APP_NAME ENV_VAR_NAME ENV_VAR_VALUE
    cf set-env pal-tracker welcome.message "Hi There"
    
  12. Unset environment from Command Prompt

    cf unset-env APP_NAME ENV_VAR_NAME
    
  13. Viewing app info
    cf app APP_NAME
    
  14. Scaling app – Vertical Scaling app instance has more memory or disk space
    -m allows to set memory space for app
    -f forces the app to restart

    cf scale APP_NAME -m 768Mb -f
    
  15. Scaling app – Horizontal Scaling more app instances serving requests
    Allows to set no of Instances

    cf scale APP_NAME -i 2