PowerShell - Gitlab repository creation

Опубликовано: 22 Июнь 2021
на канале: Mr Automation
650
4

(How to automatically create a gitlab project with branches and data)
In this video I demonstrate how you can automatically create gitlab projects with powershell. the script should work on any git backend. I am using an SSH connection (Paegent) from Windows to push my files to gitlab.

*create a git project automatically
*create a git repository automatically
*create a git project from code
*create a git repo from code
*create a git repository from code
*git add
*putty
*peagent
*git comit
*git branch
*powershell
*learn powershell
*automation
*learn automation
*windows
*windows powershell
*automatic deployment
*automatic installations
*configuration as code


Code :

param (
[Parameter(Mandatory=$true)] [string] $projectname,
[Parameter(Mandatory=$false)] [string] $localProjectDir = 'D:\GIT',
[Parameter(Mandatory=$false)] [string] $namespace = "JenkinsPipelines",
[Parameter(Mandatory=$false)] [string] $gitserver = "yourserver.com"
)

try {
Set-Location $localProjectDir -ErrorAction Stop
}
catch {
Write-Error "$localProjectDir was not found"
exit 1
}

git init $projectname

cd $projectname

new-item readme.md
new-item Jenkinsfile
new-item Scripts -ItemType Directory
new-item Configs -ItemType Directory

$jenkinstemplate = @"
//Auto Created by powershell.
pipeline {
agent {
node {
label 'windows'
}
}
stages{
stage('Stage1'){
steps {
script{
echo "Stage 1"
}
}
}
}
}
"@

#$jenkinstemplate | out-file Jenkinsfile -Encoding utf8 Jenkins cant handled utf8, pipeline will break
$jenkinstemplate | out-file Jenkinsfile -Encoding ascii #seems like Jenkins accept old school ascii

git add *

git status
git commit -a -m "Auto created by Powershell"

git branch test
git branch acceptance
git branch production
git checkout test

git branch -d master

#$protocol = "http://"
$protocol = "git@"

git remote add origin $protocol$gitserver/$namespace/$projectname.git
git remote -v
git push origin test

git push --set-upstream "$protocol$gitserver`:$namespace/$projectname.git" test
git push --set-upstream "$protocol$gitserver`:$namespace/$projectname.git" acceptance
git push --set-upstream "$protocol$gitserver`:$namespace/$projectname.git" production


Смотрите видео PowerShell - Gitlab repository creation онлайн, длительностью часов минут секунд в хорошем качестве, которое загружено на канал Mr Automation 22 Июнь 2021. Делитесь ссылкой на видео в социальных сетях, чтобы ваши подписчики и друзья так же посмотрели это видео. Данный видеоклип посмотрели 650 раз и оно понравилось 4 посетителям.