API Management with GIT and Octopus - Git PUSH / Git PULL - octopus-deploy

Following on from this post of mine:
API Management with GIT
I have an API management instance running. I know API management has its own GIT repository.
I can successfully clone, change and push changes up to my API management GIT repository.
I am also running Octopus deploy and am trying to use this:
Git Push
and this:
Git Pull
To pull my code from my companies GIT repository and push to the APIM GIT repository.
The thing is, these to plugins fail immediately with an issue not being able to find file paths on the Octopus server. Also, these were written in 2014.
Is there a recommended better way to pull from your companies repo and push to APIM repository? Also, if I am pulling to Octopus, where does the code get stored before it is pushed to APIM?

In the end, I think this plug in is out of date. I ended up writing my own PowerShell GIT bash and it works a treat.
I get the APIM json code from my companies source control then push it ti the APIM GIT repository and publish it using PowerShell.

For anyone who has this issue in the future.
The cause is most likely you are trying to use the GitPull step from the octopus server, while the code behind the step makes reference to this parameter $OctopusParameters['Octopus.Tentacle.Agent.ApplicationDirectoryPath'].
This parameter seems to return an empty value. I have not tried running from a Deployment Target.
The git clone directory could be another parameter/variable specified
I am raising this with the Octopus team.

Related

How to prevent git push heroku master?

My workflow encompasses the following steps:
Git push (to BitBucket or GitHub depending on the project).
BitBucket/GitHub is integrated with CodeShip, tests are run.
If tests are ok, CodeShip automatically deploys to Heroku.
Everything works fine when, by pushing to the remote repo, the deployment tasks are triggered which ends up with the new version going live when everything is ok.
My question is:
Sometimes, I simply do a git push heroku master which defeats the whole purpose of this workflow.
How can I prevent it from happening? Is there a way to make Heroku only accept the deploy when the source is CodeShip?
After looking around for quite some time, I noticed that there are a some ways to accomplish this, all of them related to simply not giving access to the Heroku Account for the developer:
If you're a single developer ("one-man / one-woman show"):
Do not add the Heroku Remote to your Git Repository. If it is already added, remove it. That way you're not going to push to it by mistake.
If you're managing a team:
Do not give the team a user/pass to access Heroku Toolbelt. That way, the only remote repo they will have access to should be GitHub/BitBucket/Whatever.
You could just create another branch called dev and push to that branch your changes and when you are ready to deploy to heroku merge changes into master branch.
I just came accross your issue and this is what i did as quickest resolution

How to view code deployed on Heroku?

I have deployed my REST based java application on Heroku.
Everything is working fine. However I can see code on heroku dashboard as other developers working with me also want to collaborate.
Do they need to clone .git repository given in settings page of application.
Please help how to do this ?
And how to push code to bitbucket so my code doesn't get vanished?
When you create application on Heroku it automatically gets Git repo - it's a normal repo so you colleagues can just clone it (if they're added as contributors) as you said.
To push code to bitbucket, create repo there and add it as a remote to your local git configuration. Then just push to heroku remote and bitbucket remote at will. For automated solution you can consider Github Integration: https://devcenter.heroku.com/articles/github-integration

How to push from Gitlab to Github with webhooks

My Google-fu is failing me for what seems obvious if I can only find the right manual.
I have a Gitlab server which was installed by our hosting provider
The Gitlab server has many projects.
For some of these projects, I want that Gitlab automatically pushes to a remote repository (in this case Github) every time there is a push from a local client to Gitlab.
Like this: client --> gitlab --> github
Any tags and branches should also be pushed.
AFAICT I have 3 options:
Configure the local client with two remotes, and push simultaneous to Gitlab and Github. I want to avoid this because developers.
Add a git post-receive hook in the repository on the Gitlab server. This would be most flexible (I have sufficient Linux experience to write shell scripts as git hooks) and I have found documentation on how to do this, but I want to avoid this too because then the hosting provider will need to give me shell access.
I use webhooks in Gitlab. I am unfamiliar with what the very basics of webhooks are, and I am unable to locate understandable documentation or even a simple step-by-step example. This is the documentation from Gitlab that I found and I do not understand it: http://demo.gitlab.com/help/web_hooks/web_hooks
I would appreciate good pointers, and I will summarize and document a solution when I find it.
EDIT
I'm using this Ruby code for a web hook:
class PewPewPew < Sinatra::Base
post '/pew' do
push = JSON.parse(request.body.read)
puts "I got some JSON: #{push.inspect}"
end
end
Next: find out how to tell the gitlab server that it has to push a repository. I am going back to the GitLab API.
EDIT
I think I have an idea. On the server where I run the webhook, I pull from GitLab and then I push to Github. I can even do some "magic" (running tests, building jars, deploying to Artifactory,...) before I push to GitHub. In fact it would be great if Jenkins were able to push to a remote repository after a succesful build, then I wouldn't need to write my own webhook, because I'm pretty sure Jenkins already provides a webhook for Gitlab, either native or via a plugin. But I don't know. Yet.
EDIT
I solved it in Jenkins.
You can set more than one git remote in an Jenkins job. I used Git Publisher as a Post-Build Action and it worked like a charm, exactly what I wanted.
would work of course.
is possible but dangerous because GitLab shell automatically symlinks hooks into repositories for you, and those are necessary for permission checks: https://github.com/gitlabhq/gitlab-shell/tree/823aba63e444afa2f45477819770fec3cb5f0159/hooks so I'd rather stay away from it.
Web hooks are not suitable directly: they make an HTTP request with fixed format on certain events, in your case push, not Git protocol requests.
Of course, you could write a server that consumes the hook, clones and pushes, but a service (single push and no deployment) or GitLab CI (already implements hook management) would be strictly better solutions.
services are a the best option if someone implements it: live in the source tree, would do a single push, and require no extra deployment overhead.
GitLab CI or othe CIs like Jenkins are the best option currently available. They are essentially already implemented server for the webhooks, which automatically clone for you: all you have to do then is to push from them.
The keywords you want to Google for are "gitlab mirror github". That has led me to: Gitlab repository mirroring for instance. There seems to be no perfect, easy solution today.
Also this has already been proposed at the feature request forum at: http://feedback.gitlab.com/forums/176466-general/suggestions/4614663-automatic-push-to-remote-mirror-repo-after-push-to Always check there ;) Go and upvote the request.
The key difficulty now is how to store the push credentials.
I solved it in Jenkins. You can set more than one git remote in an Jenkins job. I used Git Publisher as a Post-Build Action and it worked like a charm, exactly what I wanted.
I added "-publisher" jobs that run after "" is built successfully. I could have done it in one job, but I decided to split it up. The build jobs are triggered by a web hook in GitLab; the publisher jobs are using a #daily schedule from the BuildResultTrigger plugin.

How to set up an existing Git client repository (connected to a remote) AS a Git server repository (i.e., another repository's remote) on Windows?

I have an existing Git repository, with working copy, connected to a GitHub remote repository (my local repository is on Windows).
I would now like to allow another developer to clone my local repository and connect to it as its remote repository.
Is this possible?
I have installed GitStack for Windows, but I see only the possibility of creating a new repository - not setting up an existing local repository to be used as a remote repository for another repository.
If this is not possible, is there some way I can set up my Git infrastructure so that I can achieve the same end - i.e., so that when the other developer commits, I do not have to do anything and those commits appear in my existing Git repository?
Yes, a regular Git repository (non-bare, with a working copy) can be cloned.
For example, assume your existing repository exists at C:\my-repo\. You can clone it to C:\my-repo2\ like this:
cd /d c:\
git clone my-repo my-repo2
Cloning it from another machine is a bit different, since you need to open up a network path to your existing repository. On a Linux system I would recommend enabling SSH or using git instaweb. Of course, both of these can work on Windows, but setting them up isn't nearly as easy.
Looking through the documentation for GitStack, you probably want to follow these instructions for importing an existing repository. Point GitStack at your existing clone and you should be good to go.
A note on pushing
As Hashem Qolami points out, by default the non-bare repository will not accept a push to its active (checked-out) branch. You have a few options here.
Read about receive.denyCurrentBranch in git help config and decide whether you want to enable pushes to the checked out branch. I wouldn't recommend changing this setting, but it should be mentioned as an option.
Have downstream developers push to a different set of branches. For example, decide that downstream developers will push to branches called developer-name/branch-name. Then merge the branches in the upstream repository.
Instead of having downstream developers push into the upstream repository, enable incoming Git connections to downstream machines as well and fetch (or pull) downstream changes into the upstream repository.

Generate documentation on commit

What is the best practice for automatically-generating ruby documentation as part of a git commit workflow? We'd like to automatically generate new documentation whenever a commit is merged into master.
Use Git hooks.
If you want it to run on the client side, use a post-commit hook. Essentially, registering a hook (by storing it in .git/hooks) makes Git call an arbitrary script you provide after each successful git commit. Your script can then call RDoc or YARD to generate docs into some output directory (outside your source code repository, of course).
Alternatively, you can have it run on the server hosting your Git repo, using a post-receive hook. This will run after you push to the server's repo. For example, you could use this to automatically upload the new docs to /docs/dev/ on your project's web server.
For detailed instructions, see the chapter on hooks in the Git manual.

Resources