Should I use `git push -force` in my build step

I have a bitbucket repo that uses bitbucket pipelines to deploy to a local repository on azure (for our development server). I am working on a build step to be used by pipelines before deploying it to azure. The only thing my build step is doing right now is outputting the embedded files to a given directory, which is gitignored. Then it adds the gitignored build folder. It then amends the commit that invoked the pipeline and finally forces commit to master.

So my file looks something like this:

# bitbucket decided to make the repository shallow this line
# makes the repo unshallow so we can push later
- git fetch  https://<bitbucket-repo> --unshallow
# doing some setup so we can run the build scripts
- npm install
- npm install -g gulp
# just building files for now we can add tests in later
- npm run build:single
# forcing the build files to be included in the commit
# so that azure has access to the files.
- git add --force public/build/ 
# do some git configuration so it will let us commit
- git config --global user.email $GIT_USER_EMAIL
- git config --global user.name "\$GIT_USER_NAME"
# add to the last commit so we can keep its message
# this is so we can see the last commit message that was
# done on azure without creating a new commit message
# this command edits the previous commit and should
# never be done when that commit has already been 
# pushed to your target branch and if your target branch is
# public.
- git commit --amend --no-edit
# the below line pushes to a branch on azure we setup as a local branch
- git push --force https://<azure-branch-repo> master

      

My question is:

Am I going to break anything with this git workflow? And are there any suggestions you have?

I suppose only my script pipelines will push to the azure local repo so it's good to fix a commit that would otherwise be a bad idea if someone else pushes to it. Is this what I should be worried about? I would like to keep the original commit message as azure displays it in the list of previous deployments. If they all have deployment names correlated with their bitbucket, it makes it easier to revert to a specific deployment.

I was also wondering if this was the right time to use git push --force

it as I hear the flag --force

is considered dangerous. Since I am collecting build files for git for each deployment, I will have a commit that is removed from the repo with all the build files. My thought was to use --force

that will forget the last wandering commit and just have everything like the bitbucket pipelines built it. I'm not sure if my interpretation is correct --force push

.

+3


source to share


1 answer


you should notice that this is for my development servers. It's set up to be automated so it's less of a hassle during development, but we copy the files manually during deployment to production

However, Git is not designed to deploy or store a build artifact that can be generated. What I suggested in the " Separate deployment and deployment of Git repositories " section is to publish your artifacts (binaries in the build folder) to the artifact repository .



It doesn't have to be Nexus: see " Build and Deploy Your Java Application in an Azure Web Application " which uses FTP (taken from the Azure Web Applications main page on Azure portail ).

+6


source







All Articles