Azure DevOps - commit to Bitbucket repository updated file on release pipeline? - npm

I have an npm source code that needs to be built and push to npmjs repository. In details it looks like:
Build pipeline:
1) Get sources from Bitbucket repository
2) Get from package.json version number (ex. 0.0.3), increase it by 0.0.1 (0.0.4) and add this value to build variables $(version)
3) Make NPM install and build.
4) Take package-0.0.4.tgz and package.json to the artifacts folder and publish it.
Release pipeline:
1) Download artifacts
2) Extract package-0.0.4.tgz to npm-publish folder
3) Copy package.json to npm-publish folder
4) Publish npm folder to npmjs repository.
My question - is it possible to commit to Bitbucket repository updated package.json file with new version after publishing to npmjs repository?

It is possible to commit to Bitbucket repository. You only need to add a script task to execute the git commands.
For below example. I add a powershell task to run below commands in the pipeline to commit changes and push to the Bitbucket repo.
- powershell: |
git config --global user.email "you#example.com"
git config --global user.name "user.name"
#echo "some-text" > filename.txt
git add .
git commit -m "update package version"
git push https://username:password#bitbucket.org/name/repo.git HEAD:master -q
#if your password or username contain # replace it with %40
displayName: 'push to bitbucket'

Related

Github pages deploy vue project

I am successfully done deploy to github pages and I have an Active status of deployment. But I can't see my app. And I don't understand what is the promlem:
https://hikkiyarik.github.io/
My repo:https://github.com/HikkiYarik/HikkiYarik.github.io
I solved a problem. We need SSH key for your GitHub account, deploy.sh file and two repos like my repos foodshop and HikkiYarik.github.io.
My GitHub account for example:
https://github.com/HikkiYarik
Look closely at the contents of the file deploy.sh:
<git push -f git#github.com:HikkiYarik/HikkiYarik.github.io.git master:gh-pages>
This means we push our project that was built in the foodshop repo to the HikkiYarik.github.io repo.
By the way, gh-pages branch is created automatically. Script deploy.sh starts running when we write the command:
npm run deploy
For the command to work, just write a package.json file in scripts:
"deploy": "sh deploy.sh"

How should I use Jfrog artifactory in Dockerfile for npm install

We are using JFrog Artifactory for NPM Packages in our Jenkins CI Pipeline.. I would like to download npm packages from Artifactory while building docker images in our CI for npm ci/npm install step to decrease the duration of docker build process.
I tried as below via copy the .npmrc file that contains our private registry informations from local to docker container and when I checked the logs of npm install it able to download the dependencies from our JFrog Artifactory.. But this is not a secure approach cause I do not want to keep .npmrc in local repository and commit to the VCS.
What might be the best approach of doing this ?
Dockerfile
FROM node:12.21.0-alpine3.12 AS builder
WORKDIR /usr/src/app
ARG NPM_TOKEN
ARG NODE_ENVIRONMENT=development
ENV NODE_ENV=$NODE_ENVIRONMENT
COPY package.json /usr/src/app/package.json
COPY package-lock.json* .
COPY .npmrc /usr/src/app/.npmrc
RUN npm ci --loglevel verbose
RUN rm -f .npmrc
FROM node:12.21.0-alpine3.12
WORKDIR /usr/src/app
RUN apk update && apk add curl
COPY --from=builder /usr/src/app /usr/src/app
COPY . .
EXPOSE 50005 9183
CMD [ "npm", "run", "start:docker" ]
.npmrc
registry=https://artifacts.[company].com/artifactory/api/npm/team-npm-development-virtual
_auth = xxxxxxxxxx
always-auth = true
email = firstname.lastname#company.com
You can store your .npmrc on your VCS as long as it doesn't contain the "_auth" entry.
On azure devops we use service connections.
On "build containers" it wouldn't be possible, AFAIK.
So my approach would be using a protected build variable, to store the credential, and inject it in build time. Right before npm install you can set the "_auth" value on .npmrc.
You can achieve this in many different ways, but this is it.

gitlab runner doesn`t work on a specific project

I registered 11 projects of GitLab runner. Runners of each project work fine except 1 project. First time I registered runner of this project, it works.
But after I commit/push some changes, an error occurs and failed job.
I saw some solutions that upgrading the git version solved a problem, but I don't think so. Because all of the runners work fine except this project.
Server OS: CentOS 7
git: 1.8.3.1
First time registered runner
>Running with gitlab-runner 11.9.2 (...)
on (...)
Using Shell executor...
Running on localhost.localdomain...
Initialized empty Git repository in /home/gitlab-runner/(...)/.git/
Clean repository
Fetching changes with git depth set to 50...
Created fresh repository.
From https://gitlab.com/(...)
* [new branch] master -> origin/master
Checking out (...) as master...
Skipping Git submodules setup
$ echo "> gitlab-ci started"
> gitlab-ci started
$ cd /home/(..)
$ echo "> git pull started"
> git pull started
$ git pull
remote: Total 0 (delta 0), reused 0 (delta 0)
Already up-to-date.
Job succeeded
Second commit/pull, then
>Running with gitlab-runner 11.9.2 (...)
on (...)
Using Shell executor...
Running on localhost.localdomain...
Reinitialized existing Git repository in /home/gitlab-runner/(...)/.git/
Clean repository
Fetching changes with git depth set to 50...
fatal: remote origin already exists.
fatal: git fetch-pack: expected shallow list
ERROR: Job failed: exit status 1
edit. here is my .gitlab-ci.yml
stages:
- deploy
deploy_to_master:
stage: deploy
script:
- echo "> gitlab-ci started"
- cd /home/www/dir
- echo "> git pull started"
- git pull
- echo "> permission set"
- chmod 707 -R ./data/
- chmod 707 -R ./plugin/nice/
- chmod 707 ./favicon.ico
- echo "> server reload(=httpd -k graceful)"
- systemctl reload httpd
only:
- master
tags:
- tags
There are a few options to fix this. The problem is the version of git on your runner is too old. And sometimes you can't update git on the runner.
Options to fix:
Upgrade to a newer version of git on the runner.
In .gitlab-ci.yml, use the option to git clone:
variables:
GIT_STRATEGY: clone
Configure Gitlab, change Git strategy for pipelines of the project to "git clone".
3.1. In the Gitlab web gui,
3.2. go to your project,
3.3. then: "Settings -> CI / CD -> General pipelines".
3.4. Change the options for:
"Git strategy for pipelines" to: "git clone"
"Git shallow clone" to: 0
Centos 7 ships with git version 1.8.3.1 . This version doesn't support commands like git fetch-pack . To fix this problem, you could update git on your server from the IUS repository.
update git on Centos 7 to version 2 from third-party IUS repo
$ git --version
git version 1.8.3.1
sudo yum -y install https://packages.endpointdev.com/rhel/7/os/x86_64/endpoint-repo.x86_64.rpm
sudo yum install git
You can go around this problem without upgrading git at all:
1. Clone Strategy
Set in .gitlab-ci.yml:
variables:
GIT_STRATEGY: clone
Now every change you make will trigger re-cloning the project, avoiding the need of the problematic git fetch-pack command.
2. Manually Remove Project Directory (not recommended)
Remove manually the build directory from gitlab-runner server, so it will have to clone it again.
For project testgroup/testproject, run:
careful with rm commands!
rm -rf /home/gitlab-runner/builds/UwnzuxxL/0/testgroup/testproject
Notice that after builds directory you have a random string that will be different from this example.
Check value in your project's CI/CD settings on gitlab.com. If there is any value in 'git shallow clone' remove it and save changes. Now your pipeline will work as expected.
I had a similar issue, and I had to update Git. Centos 7 comes with git-1.8.x which has limitations around gitlab-ci.
Upgrade your git, based on this guide.
I made a new project and, finally, it works fine. I don't know why the other one didn't work. If the same problems occurs like mine, don't get too serious: Just make a new gitlab project. It is good for your mental well-being.
rm -fr /home/gitlab-runner/(...) , clean then exists repository

How to import local git repository into svn?

I am working on local git repository and I need to push my local git into existing svn repository. My git repository is pure local git repository, it was not init using git svn clone.
How can I import this local git repo into svn?
Preferably I'ld like to keep the git history being imported into SVN.
Currently the SVN repository is structure as:
https://svnrepohost
/branches
/tags
/trunk
/projectA
/projectB
/newProject
What I need it is to import my git repository into the https://svnrepohost/trunk/newProject above, assuming the newProject folder is empty.
I have finally solved this problem by the following steps:
Setup appropriate project folder in svn to be imported to, for example http://svnrepo/svn/trunk/newProject
Create a new git-svn repository
git svn clone http://svnrepo/svn/trunk/newProject
Add the git repo that we want to import as remote to the new git-svn repo
git remote add origin ../original-git-repo
Pull all the data from original-git-repo
git pull origin master --allow-unrelated-histories
Rebase local repository against svn
git svn rebase
Commit the changes into svn
git svn dcommit
Clean up the remote
git remote delete origin
The easiest way to do this is to just svn import the Git directory. That will lose you your Git commit history, however.
First of all, make sure the .git directory won't be imported by setting the global-ignores in the Subversion config file. Open your ~/.subversion/config file (that'll be in something like C:\Users\username\.subversion\config on Windows), find the section starting [miscellany], and add a line directly underneath reading as below:
global-ignores = .git
(if you already have a line with global-ignores = that doesn't have a # in front of it, then just add .git to the end of that line.)
Next, run the below:
svn import <path-to-local-git-repository> https://svnrepohost/trunk/newProject
That should copy the contents of the local Git repository onto the server exactly where you want it.
You may use SubGit.
$ svnadmin create repo.svn
$ subgit configure repo.svn
...
CONFIGURATION SUCCESSFUL
Adjust '/tmp/repo.svn/conf/subgit.conf' file
and then run
subgit install "repo.svn"
to complete SubGit installation.
$ nano repo.svn/conf/subgit.conf #edit to set git.default.repository=path/to/your/bare/git/repository
$ subgit install repo.svn
I would also recommend you to create a bare clone of your Git repository and to specify path to it (in git.default.repository) instead of your original repository. I.e.
$ git clone --bare path/to/your/original/repository path/to/your/bare/git/repository
After "subgit install" command the repositories (repo.svn and repo.git) will be in continuos synchronization (triggered by pre-receive hook in Git [that starts on pushing to your bare repository] and pre-commit in SVN). To stop synchronization you may run
$ subgit uninstall repo.svn
git svn clone http://svnrepo/svn/trunk/newProject
git remote add origin ../original-git-repo
git fetch origin
git checkout -b lmaster remotes/origin/master
git rebase master
git svn rebase
git svn dcommit

Restart Git repo Xcode 4.3.2

For different changes I made in my project, I need to restart Git repo and start with a new fresh version with the current project. How can I achieve this?
Many thanks
fire up your terminal:
go to project
cd myPath/MyProject
delete the current repo on your disk - your git repo = RIP
rm -Rf .git
init a new repo
git init
add your project to the new git repo
git add .
commit
git commit -a -m "init Project XY"
check if the repo is o.k
git status
What you want to do is create a new empty branch without any history. That way you start fresh but still have the option to return to your previous content. Inside the git repository, enter these commands:
git symbolic-ref HEAD refs/heads/<branchname>
rm .git/index
git clean -fdx
After that you are in the same situation as with an empty repository (i.e. start adding and commiting files) except that the history still exists in your old branches.
Note that all files you don't have in your old version will be permanently removed.