windows 下配置 gitlab-runner 及编译可执行程序

linux 上安装 gitlab

安装方式:

  • Install on Linux
  • Install on Kubernetes
  • Install with Docker
  • Compile from source
  • Install from cloud provider

Install on Linux

GitLab下载安装_GitLab安装和配置_GitLab最新中文官网免费版下载-极狐GitLab

1. 安装和配置所需的依赖

sudo apt-get update
sudo apt-get install -y curl openssh-server ca-certificates tzdata perl

注释:

配置电子邮件通知:见附

2. 下载并安装极狐GitLab

执行以下命令配置极狐GitLab 软件源镜像。

curl -L get.gitlab.cn | bash

指定域名安装,此处http,EXTERNAL_URL可不设置

sudo EXTERNAL_URL="http://gitlab.example.com" apt-get install -y gitlab-jh

报错:

GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your JiHu GitLab instance by setting external_url
configuration in /etc/gitlab/gitlab.rb file.
Then, you can start your JiHu GitLab instance by running the following command:
sudo gitlab-ctl reconfigure

解决:执行配置

gitlab-ctl reconfigure
gitlab-ctl restart

其他命令:

gitlab-ctl stop

注释:

配置https和其他:见附

3. 登录极狐GitLab 实例

使用第二步 EXTERNAL_URL 中配置的地址来访问安装成功的极狐GitLab 实例。用户名默认为 root 。如果在安装过程中指定了初始密码,则用初始密码登录,如果未指定密码,则系统会随机生成一个密码并存储在 /etc/gitlab/initial_root_password 文件中, 查看随机密码并使用 root 用户名登录。

注意:出于安全原因,24 小时后,/etc/gitlab/initial_root_password 会被第一次 gitlab-ctl reconfigure 自动删除,因此若使用随机密码登录,建议安装成功初始登录成功之后,立即修改初始密码。

信息:

http://localhost
http://ip
修改密码:123456

4. 后续配置

完成安装后,请参考建议的后续配置,包括身份验证选项和注册限制的配置。

windows 上安装 gitlab-runner

安装

Install GitLab Runner on Windows | GitLab Docs

1. 创建文件夹

E:\GitLab-Runner

2. 下载二进制程序

64-bit or 32-bit

放到E:\GitLab-Runner

改名为gitlab-runner.exe(可选)

3. 确保权限

E:\GitLab-Runner文件夹和exe程序确保限制写权限。如果不设置这些权限,普通用户可以替换可执行文件,并以提升的权限运行任意代码。

4. 运行命令行

Starting Windows PowerShell - PowerShell | Microsoft Learn

5. 注册一个 runner

# 注册命令
.\gitlab-runner.exe register
# 输入url
http://ip
# token
GR1348941GDbRfggTDey1yfCDayQw
# 配置文件
E:\\GitLab-Runner\\config.toml

或者,使用非交互模式

.\gitlab-runner.exe register \
  --non-interactive \
  --url "https://gitlab.com/" \
  --token "$RUNNER_TOKEN" \
  --executor "docker-windows" \
  --docker-image mcr.microsoft.com/windows/servercore:1809_amd64 \
  --description "docker-runner"

6. 安装 runner 为服务并启动

使用内置系统账号(推荐)或用户账号

内置系统账号

cd E:\GitLab-Runner
.\gitlab-runner.exe install
.\gitlab-runner.exe start

或用户账号

cd E:\GitLab-Runner
.\gitlab-runner.exe install --user ENTER-YOUR-USERNAME --password ENTER-YOUR-PASSWORD
.\gitlab-runner.exe start

7. 可选(并行配置)

参考: advanced configuration details

配置文件:E:\GitLab-Runner\config.toml

使用

在windows上编译 c 程序

使用 MinGW

是什么:

MinGW项目(官方网站)是Minimalist GNU for Windows的缩写,是本地Windows应用程序的极简主义开发环境,该项目旨在将gcc编译器移植到Windows系统上

安装:

最新!MinGW-w64的下载与安装(超详细!!!) - 知乎

示例:

hello.c

/* file hello.c */
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	/* 打印Hello World */
	printf("Hello World.\n");

	/* 程序暂停,便于观察结果 */
	system("pause");
	
	/* 程序返回,结束 */
	return 0;
}

编译:

gcc hello.c
a.exe

安装make

在windows上安装make - 知乎

Makefile

hello.exe:hello.c
	gcc hello.c -o hello.exe

编译运行

make
hello.exe

使用 MSVC

  • MinGW-w64 是一个 Windows 平台的 GCC 编译器工具链,支持编译 Windows 应用程序。
  • Visual Studio 2019 通常使用 MSVC(Microsoft Visual C++)编译器,而 MinGW-w64 使用 GCC 编译器。

示例:还是需要安装 Visual Studio 2019

stages:
  - build

build_windows:
  stage: build
  tags:
    - windows  # 使用 Windows 环境的 Runner
  script:
    - echo "Setting up MSVC environment..."
    - call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
    - echo "Building with MSVC..."
    - cl /EHsc /Fe:myprogram.exe myprogram.c
  artifacts:
    paths:
      - myprogram.exe
    expire_in: 1 week  # 制品保存 1 周

在runner里集成

.gitlab-ci.yml

stages:          # List of stages for jobs, and their order of execution
  - build

build-job:       # This job runs in the build stage, which runs first.
  stage: build
  tags:
    - lym
  script:
    - echo "Compiling the code..."
    - gcc hello.c -o hello.exe
    #- hello.exe
    - cp hello.exe hello1.exe
    - echo "Compile complete."
    - echo "make the code..."
    - make
    #- hello.exe
    - echo "make complete."
  artifacts:
    paths:
      - hello1.exe
      - hello.exe
    expire_in: 1 day  # 制品保存 1 周

报错一:

Running with gitlab-runner 17.9.0 (c4cbe9dd)

on lym t3_B1Nd5, system ID: s_b41fe35ab3ce

Preparing the "shell" executor00:00

Using Shell (pwsh) executor...

Preparing environment00:01

ERROR: Job failed (system failure): prepare environment: failed to start process: starting OS command: exec: "pwsh": executable file not found in %PATH%. Check https://docs.gitlab.com/runner/shells/index.html#shell-profile-loading for more information

解决:

修改配置文件:config.toml

executor = "shell"
shell = "pwsh" # 此行pwsh改为powershell

重启

.\gitlab-runner.exe stop
.\gitlab-runner.exe start

报错二:

Running with gitlab-runner 17.9.0 (c4cbe9dd)

on lym t3_B1Nd5, system ID: s_b41fe35ab3ce

Preparing the "shell" executor00:00

Using Shell (powershell) executor...

Preparing environment00:02

Running on NJZF--NFPPPONVV...

Getting source from Git repository00:05

Fetching changes with git depth set to 20...

Initialized empty Git repository in E:/GitLab-Runner/builds/t3_B1Nd5/0/circle/test/.git/

Created fresh repository.

fatal: unable to access 'http://gitlab.example.com/circle/test.git/': Could not resolve host: gitlab.example.com

Cleaning up project directory and file based variables00:00

ERROR: Job failed: exit status 128

现象:安装gitping 域名不通,ping ip能通

解决:runner机器上配置hosts中ip和域名的映射关系:windows(C:\Windows\System32\drivers\etc),linux(/etc/hosts)

ip gitlab.example.com

配置电子邮件通知

(可选)如果要使用 Postfix 来发送电子邮件通知,执行以下安装命令。

sudo apt-get install -y postfix

如果您想使用其他解决方案发送电子邮件,请跳过上面 Postfix 安装步骤并在安装极狐GitLab 后配置外部 SMTP 服务器

配置https和其他

接下来,安装极狐GitLab。安装之前,需要确保您的DNS设置正确。此外,还需要通过设置 EXTERNAL_URL 环境变量来指定极狐GitLab 实例的 URL。

如果您想通过 HTTPS 来访问实例,那么您可以根据官方文档进行配置,让实例使用 Let's Encrypt 自动请求 SSL 证书,这需要有效的主机名和入站 HTTP 访问。您也可以使用自己的证书或仅使用 http://(不带 s)。

如果您想为初始管理员用户( root )指定自定义的初始密码,可以根据文档指导进行配置。否则将默认生成随机密码。

接下来执行如下命令开始安装:

sudo EXTERNAL_URL="https://gitlab.example.com" apt-get install -y gitlab-jh

其他配置详情可以查看 Omnibus 安装配置文档

参考

GitLab Docs

posted @ 2025-03-04 20:23  circlelll  阅读(596)  评论(0)    收藏  举报