PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, September 26, 2022

[FIXED] How to get source branch from google cloud build trigger on push when merging

 September 26, 2022     continuous-deployment, github, google-cloud-build, google-cloud-platform     No comments   

Issue

I am merging 'feature-branch' onto 'dev-branch' from a github pull request. I am using a google cloud build trigger that is triggered on push to 'dev-branch'. From what I can tell in the documentation of substitution variables, there are no substitution variables to get the name of the branch that I am merging from - 'feature-branch' and only the branch that I merging to - 'dev-branch'. Is there a way or a workaround to get information (name, sha, id, etc.) of the branch that is being merged from on a google cloud build trigger from a push to branch event?


Solution

Presumably you can have some naming conventions on the first line of the commit message (happens at merge pull request "event"), so that this line includes the source (or head) branch name (the source of the merge - in your words - 'feature-branch').

Then, you can create a substitution variable:

substitutions:
  _COMMIT_MESSAGE: $(commit.commit.message)

here is a documentation link: Creating substitutions using payload bindings

And use that variable in some build step to get the the head branch name:

    mapfile -t commit_lines <<< "${_COMMIT_MESSAGE}"
    source_branch="$(echo ${commit_lines[0]} | <<add your command here following naming convention for the commit message>> )"
    echo "=> My source branch name: ${source_branch}"

After that you can use the source branch name.



Answered By - al-dann
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing