Search code examples
google-cloud-rungoogle-workflows

How to retrieve the URL of a Cloud Run service with Google Workflow?


I am used to using CI / CD architecture for my deployments on Cloud Run. Each time a deployment has taken place, I have to manually retrieve the URL that I send to my employees by email. My goal is to automate this task with Google Workflow. How do I retrieve the URL of a new service or the tag of a Cloud Run service with Google Workflow ?


Solution

  • Put together this returns the URL of a cloud run service

    - initialize:
        assign:
          - project: ${sys.get_env("GOOGLE_CLOUD_PROJECT_NUMBER")}
          - zone: us-central1
          - service: service
    - getCloudRunDetails:
        call: http.get
        args:
            url: ${"https://"+zone+"-run.googleapis.com/apis/serving.knative.dev/v1/namespaces/"+project+"/services/"+service+"?alt=json"}
            auth:
                type: OAuth2
        result: bitresult
    - returnResult:
        return: ${bitresult.body.status.address.url}
    

    the expected output is:

    argument: 'null'
    endTime: '2020-11-19T23:05:18.232772542Z'
    name: projects/<edited>describeCloudRun/executions/<edited>   
    result: '"https://<edited>uc.a.run.app"'
    startTime: '2020-11-19T23:05:17.769640039Z'
    state: SUCCEEDED
    workflowRevisionId: 000020-b11
    

    You have your value inside the result key.