Linux Programmer | RHCE | RHCSA

Search This Blog

Gitlab



Change Timezone in Gitlab.

The global time zone configuration parameter can be changed in config/gitlab.yml:
# time_zone: 'UTC'
Uncomment and customize if you want to change the default time zone
of the GitLab application.

Viewing all available timezones.

To see all available time zones, run bundle exec rake time:zones:all.
For Omnibus installations, run gitlab-rake time:zones:all.

Changing timezone in omnibus installations.

- GitLab defaults its time zone to UTC. It has a global timezone
configuration parameter in
/etc/gitlab/gitlab.rb.

- To obtain a list of timezones, log in to your GitLab application server and
run a command 
that generates a list of timezones in TZInfo format for the server.
For example, install timedatectl and run timedatectl list-timezones.
 
- To update, add the timezone that best applies to your location.
For example: gitlab_rails['time_zone'] = 'Asia/Kolkata'

- After adding the configuration parameter, reconfigure and restart your
GitLab instance:
gitlab-ctl reconfigure
gitlab-ctl restart

Get project ID from gitlab:


  • Project -> Settings -> General -> General Project -> Expand -> Project ID.


# Gitlab API 

# List protected branch of project:

curl --header "PRIVATE-TOKEN: 54KLSE-eN2hF1fAE48-" "http://gitlab-link.com/api/v4/projects/10/protected_branches"

# Protect branch:

# Unprotect branch

curl --request DELETE --header "PRIVATE-TOKEN: 0dGHsfg-eN2hF1fAE48-" "http://gitlab-link.com/api/v4/projects/10/protected_branches/QA 

Git Operations

 
## Initialize Git Repo.
sudo git init .

## Add Repository
sudo git remote add origin http://peoject-path-link

## pull Repository
sudo git fetch origin developer_branch:developer_branch
OR
sudo git pull origin developer_branch

## Remove branch from local repository
sudo git checkout developer_branch
sudo git branch -D developer_branch

## Remove branch from live gitlab
sudo git push origin --delete new_branch

## Save Credentials
sudo git config --global user.email "user@test.in"
sudo git config --global user.name "user"

## commit changes
sudo git commit -m "comments"

## Create new branch from developer branch
sudo git checkout -b new_branch developer_branch

## Merge changes to new branch
sudo git checkout developer_branch
sudo git merge --no-ff new_branch

## Set tag on new branch
sudo git checkout new_branch
sudo git tag "tag_name"

## Push new branch
sudo git push origin new_branch

Gitlab backup

Backup command:
gitlab-rake gitlab:backup:create

Backup location: 
/var/opt/gitlab/backups

Git cherry-pick

For example you want to merge one commit from master branch to QA branch.

Source : Master and Destination : QA


Steps :

1. Take pull of repository
git pull origin

2. List all commits of list specific time period commits
git log --oneline --since="2.days"

3. Copy Commit ID
4. Switch to other branch(QA) and take latest pull.
git checkout QA
git pull

5. apply commit to QA branch
git cherry-pick <commit_ID>

6. push changes to live branch
## git push

OR cherry-pick through Gitlab API

First get the private-token of your gitlab user.

1. Login gitlab -> Nagigate to "User settings".

2. Click "Access Tokens" from the left panel.

3. Enter name of access token, select expiry date, select all scopes and click on "Create personal Token".

4. Copy Token and place it on safe place.

List all commits:

curl --header "PRIVATE-TOKEN: <TOKEN>" "http://<gitlab-ip>/api/v4/projects/$project_id/repository/commits?ref_name=$branch" | jq '.[]' | jq -r '.short_id + " - " + .title'

Cherry-pick commit to specific branch:

curl --header "PRIVATE-TOKEN: <TOKEN>" --form "branch=<master/QA>" "http://domain-name/api/v4/projects/<$project_id>/repository/commits/<$commit_ID>/cherry_pick"

Protected Branch Access Role change

You can't directly edit the Protected branch roles through API. there is trick to edit so.

you need to delete the role first and then recreate new with changed roles.

Below are the values for roles:

Developers - 30

Maintainers + Developers - 40

No one - 0

Remove Access to every one:

curl --request DELETE --header "PRIVATE-TOKEN: $Git-token" \

    "$GITLAB-LINK/api/v4/projects/$ProjectID/protected_branches/master"


curl --request POST --header "PRIVATE-TOKEN: $GitlabToken" "$GITLAB-LINK/api/v4/projects/$PID/protected_branches?name=master&push_access_level=0&merge_access_level=0"


Re-create with Developers+Maintainers permission:

curl --request DELETE --header "PRIVATE-TOKEN: $Git-token" \

    "$GITLAB-LINK/api/v4/projects/$ProjectID/protected_branches/master"


curl --request POST --header "PRIVATE-TOKEN: $GitlabToken" "$GITLAB-LINK/api/v4/projects/$PID/protected_branches?name=master&push_access_level=30&merge_access_level=30"


Gitlab Upgrade:

https://impurval.blogspot.com/2024/01/gitlab-community-version-upgrade-from.html

No comments:

Post a Comment

SSH not working with password after upgrade ubuntu 22.04

Issue: In recent upgrade of ubuntu 22.04 we are not able to login server with SSH password. but when we try to login with key then it allow...