Push to Private Google repositories
Try to put by command like this:
steps:
- name: 'gcr.io/cloud-builders/git'
entrypoint: 'bash'
args:
- '-c'
- |
touch ./some-file.txt
git config --global user.name batman
git config --global user.email batman@gotham.city
git add -A
git commit -m 'batmans commit'
git push 'https://source.developers.google.com/p/$PROJECT_ID/r/my-repo' master
Or put them in script file like this:
steps:
- name: gcr.io/cloud-builders/git
args: ["sh", "git.sh"]
Or change alpine
to python
like this:
steps:
- name: python
args: ["sh", "git.sh"]
Or write it using the config elements like this:
steps:
- name: python
entrypoint: /bin/sh
args: ['-c', './git.sh]
Then put all of your build steps in the git.sh
file:
#!bin/sh
sh ./some-file.txt
git config --global user.name batman
git config --global user.email batman@gotham.city
git add -A
git commit -m 'batmans commit'
git remote set-url origin 'https://source.developers.google.com/p/$PROJECT_ID/r/my-repo'
git push origin master
Push to Private GitHub repositories
If you want to push the repo to Github you can run the builder with kms service
along with ssh-agent
and or expect
. Then simulate the git interaction to private GitHub repositories like this:
steps:
- name: 'gcr.io/cloud-builders/gcloud'
args: ['kms', 'decrypt', '--location', 'global',
'--keyring', 'my-keyring','--key', 'github-key',
'--ciphertext-file', 'id_rsa.enc', '--plaintext-file', '/root/.ssh/id_rsa']
volumes:
- name: 'ssh'
path: /root/.ssh
- name: 'python'
entrypoint: 'bash'
args: ['-c', './git.sh]
volumes:
- name: 'ssh'
path: /root/.ssh
Similar with above you can put steps also resource in the git.sh
file:
#!bin/sh
chmod 600 /root/.ssh/id_rsa
cat <<EOF >/root/.ssh/config
Hostname github.com
IdentityFile /root/.ssh/id_rsa
EOF
mv known_hosts /root/.ssh/known_hosts
apt-get update
apt-get --assume-yes install expect
git config --global <github:user.name>
git config --global <github:user.email>
eval `ssh-agent` && expect agent_builder && ssh-add -l
cd /path/to/my-repo
git add .
git commit -m 'batmans commit'
git remote set-url origin 'git@github.com:my-user/my-repo.git'
git push origin master
The file agent_builder
contains the following codes:
#!/usr/bin/expect -f
spawn ssh-add /root/.ssh/id_rsa
expect "Enter passphrase for /root/.ssh/id_rsa:"
send "my-passphrase\n";
expect "Identity added: /root/.ssh/id_rsa (/root/.ssh/id_rsa)"
interact
When you set mirror configuration
then the commits that you push to the GitHub repository are copied, or mirrored, back into Google repository hosted in Cloud Source Repositories.