Home > database >  Need to push the .yml file into multiple repositories with custom modifications
Need to push the .yml file into multiple repositories with custom modifications

Time:09-03

I have developed a shell script that help me to add source.yml file to all repos but i got struck with few blocks

need to push to all git repos (100) ie. how to add that source.yml file to all repos How to update the given below variable 1,2 from metadata according to the repo name for suppose repo name is developer then the metadata inside source.yaml file, the variable-1,2 should be replace with developer.

Here the scenario

I need to add a source.yml file into multiple repositories(100) with variable configuration

In .yml file, metadata consists of projectKey(variable-1(Current-reponame)) & FriendlyName(variable-2(current-reponame))where these variable values should change according to repo name

apiVersion: v9
metadata:
askId: ABCDE123-45678
caAgileId: ABC
//com.ABC is common for all repos (yourproduct.yourApp.yourComponent) 
variable-1(current repo name)
// (YourApp-SomeComponent) - variable-2(current repo name)
projectKey: com.ABC.yourproduct.yourApp.yourComponent
FriendlyName: YourApp-SomeComponent
componentType: code
targetQG: GATE_77

Please help me with how to push the .yml file into multiple repositories over multiple organisations

#!/bin/bash
cd $baselocation "https://github.com/xxxxxxx-xxxx/"
repocount='gitrepo.csv | wc -l'
for i in 'gitrepo.csv'
do 
 reponame="$i"
 cd $baselocation/$i
 cp source.yaml .
 git add .
 git commit -m "Create source.yaml"
 done

CodePudding user response:

Heh, I just did something similar. Here's the meat of the problem, where I have all the repos checked out in the current directory.

I don't particularly recommend this, but it's something I threw together in five minutes for a task I had this weekend.

#!/bin/bash

target=some_file.yml
message="Update YAML file"

ls */.git | perl -lpe 's|/.*||' | while read -r line
do
    pwd
    git checkout master
    git pull
    ... update the target here ...
    git diff --exit-code $target
    if [ $? -eq 0 ]
    then
      echo "NO CHANGES"
      continue
    fi
    git add $target
    git commit -m "$message" $target
    git push origin $branch 2>&1
done

CodePudding user response:

#!/bin/bash
for i in `cat youfile.csv`
do
 base_location="Directory path"
 reponame=${i}
 echo ${reponame}
 cp Directory path/source.yaml Directory path/tmp/source.yaml
 cd ${base_location}
 mkdir ${reponame}
 cd ${reponame}
 sed -e "s/Variable-1,2/$reponame/g" '/Directory path/tmp/source.yaml'
 git init
 git clone https://[email protected]/yourusername${i}.git
 cd ${reponame}
 cp Directory path/tmp/source.yaml .
 git add source.yaml
 git commit -m "Create source.yaml"
 git push --set-upstream $reponame master
 rm Directory path/tmp/source.yaml
 cd Directory path
done
  • Related