我正在开发一个python项目并使用miniconda来管理我的环境.我使用GitLab进行CI以及以下运行器配置
stages:
- build
- test
build:
stage: build
script:
- if hash $HOME/miniconda/bin/conda 2>/dev/null;
then
export PATH="$HOME/miniconda/bin:$PATH";
else
wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh;
bash miniconda.sh -b -p $HOME/miniconda;
export PATH="$HOME/miniconda/bin:$PATH";
fi
- conda update --yes conda
test:
stage: test
script:
- conda env create --quiet --force --file environment.yml
- source activate myenv
- nosetests --with-coverage --cover-erase --cover-package=mypackage --cover-html
- pylint --reports=n tests/test_final.py
- pep8 tests/test_final.py
- grep pc_cov cover/index.html | egrep -o "[0-9]+\%" | awk '{ print "covered …Run Code Online (Sandbox Code Playgroud) 我一直在尝试使用安装在 macOS 设备上的 Docker Runner 来设置 GitLab CI,以处理对我的 Android 项目的测试。Docker 已安装并在 Mac 上运行,Gitlab 将启动作业,但在构建阶段失败并显示错误
chmod:无法访问“./gradlew”:没有那个文件或目录错误:作业失败:退出代码 1
我已经尝试了 GitLab CI 中包含的 Android 模板 .yml 文件以及在线找到的其他文件,我当前的 .yml 配置是:
image: jerbob92/gitlab-ci-android:latest
before_script:
- export GRADLE_USER_HOME=`pwd`/.gradle
- mkdir -p $GRADLE_USER_HOME
- chmod +x ./gradlew
cache:
paths:
- .gradle/wrapper
- .gradle/caches
build:
stage: build
script:
- ./gradlew assemble
test:
stage: test
script:
- ./gradlew check
Run Code Online (Sandbox Code Playgroud)
无论我使用什么配置,Runner 在 chmod +x ./gradlew 步骤中都会失败。我在这里遗漏了一个步骤吗?
我正在尝试使用 gitlab-ci 将我的图像推送到我的 docker repositoy 存储库,但我收到错误消息:
拒绝:请求访问资源被拒绝错误:作业失败:退出代码 1
我的.gitlab-ci.yml
# This file is a template, and might need editing before it works on your project.
# Official docker image.
image: docker:latest
services:
- docker:dind
before_script:
- docker version
- docker-compose version
- docker login -u $USER -p $PASS index.docker.io
build-master:
stage: build
script:
- apk add --no-cache py-pip
- pip install docker-compose
- docker build --pull -t index.docker.io/$REPOSITORY .
- docker push index.docker.io/$REPOSITORY
only:
- master
tags:
- docker …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用以下命令在 EC2 实例(Ubuntu 机器)上取消注册 gitlab-runner:
sudo gitlab-runner --debug unregister --token [RUNNER-TOKEN] --url [RUNNER-URL]
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Runtime platform arch=amd64 os=linux pid=2374 revision=6fbc7474 version=13.1.1
Checking runtime mode GOOS=linux uid=0
Running in system-mode.
Dialing: tcp gitlab.com:443 ...
ERROR: Unregistering runner from GitLab forbidden runner=xv2Ng6Tc
FATAL: Failed to unregister runner
Run Code Online (Sandbox Code Playgroud) 这就是我使用 Github 的方式:
jobs:
run-tests:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./MyApp
steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build project
run: dotnet build --no-restore
- name: Run tests
run: dotnet test --no-build
Run Code Online (Sandbox Code Playgroud)
这次在 Gitlab 上,我的项目解决方案文件位于存储库的根目录中。我创建了一个.gitlab-ci.yml文件并从
image: mcr.microsoft.com/dotnet/sdk:5.0
stages:
- restore-dependencies
- build-solution
- run-tests
restore-dependencies:
stage: restore-dependencies
script:
- dotnet restore --packages packages
artifacts:
paths:
- packages
build-solution:
stage: build-solution
script:
- dotnet …Run Code Online (Sandbox Code Playgroud) 我想根据本教程为我的 C# 项目生成单个覆盖率报告
https://docs.microsoft.com/en-us/dotnet/core/testing/unit-testing-code-coverage
使用以下配置启动 Gitlab CI 管道时
image: mcr.microsoft.com/dotnet/sdk:5.0
stages:
- build
- unit-tests
build:
stage: build
script:
- dotnet build --output build
artifacts:
paths:
- build
unit-tests:
stage: unit-tests
script:
- |-
dotnet test --no-build --output build --collect:"XPlat Code Coverage";
dotnet tool install -g dotnet-reportgenerator-globaltool;
reportgenerator -reports:'**/coverage.cobertura.xml' -targetdir:'CoverageReports' -reporttypes:'Cobertura';
artifacts:
reports:
cobertura: CoverageReports/Cobertura.xml
dependencies:
- build
Run Code Online (Sandbox Code Playgroud)
我收到以下错误
报告文件模式“**/coverage.cobertura.xml”无效。没有找到匹配的文件。
ls在运行 reportgenerator 命令之前使用检查目录时,我可以看到没有匹配的文件(尽管它们应该存在)。
我希望每个测试项目有一个coverage.cobertura.xml 文件,例如
...\myRepo\xUnitTestProject1\TestResults\380e65f7-48d5-468f-9cbc-550c8e0aeda8\coverage.cobertura.xml...\myRepo\xUnitTestProject2\TestResults\c96c55f7-40d3-483e-a136-573615e3a9c3\coverage.cobertura.xml我目前的解决方案:
看来我必须再次运行构建。所以我替换了这条线
dotnet test --no-build --output build --collect:"XPlat Code Coverage";
和
dotnet …
我尝试做一个非常基本的 GitLab CI 工作。
我想要:
当我推送到开发时,gitlab 会使用标签“develop”构建 docker 镜像
当我推送到 main 时,gitlab 检查当前提交是否有标签,并用它构建镜像,否则不会触发作业。
Build and publish docker image:
stage: build
rules:
- if:
($CI_COMMIT_BRANCH == "main" && $CI_COMMIT_TAG && $CI_PIPELINE_SOURCE == "push")
variables:
TAG: $CI_COMMIT_TAG
- if:
($CI_COMMIT_BRANCH == "develop" && $CI_PIPELINE_SOURCE == "push")
variables:
TAG: develop
script:
- echo $TAG
- ...<another commands>
Run Code Online (Sandbox Code Playgroud)
但它并没有按预期工作。$CI_COMMIT_TAG - 为空。尽管触发作业(合并提交)的提交有标签。
我发现我发现的解释并不能帮助使用“if”语句实现我的目标。基于此处建议的工作流程的
解决方案也没有帮助。
使用名为 COMMIT_TAG 的变量的直观方式似乎很常见。
但它就是行不通。请好心人向我解释如何实现我的目标吗?
我在WSL Ubuntu 20中安装了Gitlab-runner。首先,我已经注册了runner并成功运行。但是当我检查 Gitlab-runner 的状态时,它显示:
namlb@Admin:/etc/init.d$ sudo gitlab-runner status
Runtime platform arch=amd64 os=linux pid=2170 revision=e0218c92
version=14.3.2
gitlab-runner: the service is not installed
Run Code Online (Sandbox Code Playgroud)
另一件让我困惑的事情是,当我已经运行gitlab-runner run命令时,我的跑步者只是执行作业,而在某些指南中,他们只需要运行gitlab-runner start,并且作业将在触发时执行。
以下是有关我的 gitlab-runner 的一些信息:
namlb@Admin:~$ sudo gitlab-runner start
[sudo] password for namlb:
Runtime platform arch=amd64 os=linux pid=2563 revision=e0218c92 version=14.3.2
namlb@Admin:~$ gitlab-runner status
Runtime platform arch=amd64 os=linux pid=2609 revision=e0218c92 version=14.3.2
FATAL: The --user is not supported for non-root users
namlb@Admin:~$ sudo gitlab-runner status
Runtime platform arch=amd64 os=linux pid=2635 revision=e0218c92 version=14.3.2
gitlab-runner: the service …Run Code Online (Sandbox Code Playgroud) 我对尝试实现 GitLab 的 CI/CD 管道完全陌生,但进展顺利。事实上,对于我的 ASP.NET 项目,如果我在msbuild使用 Web Deploy 的命令中指定发布配置文件,它实际上会将代码成功部署到 Web 服务器。
但是,我现在想让“构建”作业创建工件,将其上传到 GitLab,然后我可以随后进行部署。我们正在使用 GitLab 的自托管实例,我不是该实例的管理员,但如果我知道我要什么,我可以与管理员交谈!
所以我gitlab-ci.yml像这样配置了我的文件:
variables:
NUGET_PATH: 'C:\Program Files\Nuget\Nuget.exe'
NUGET_SOURCES: 'https://api.nuget.org/v3/index.json'
MSBUILD_PATH: 'C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\msbuild.exe'
stages:
- build
build-job:
variables:
CI_DEBUG_TRACE: "true"
stage: build
script:
- '& "$env:NUGET_PATH" restore ApplicationTemplate.sln -Source "$env:NUGET_SOURCES"'
- '& "$env:MSBUILD_PATH" ApplicationTemplate\ApplicationTemplate.csproj /p:DeployOnBuild=true /p:Configuration=Release /p:PublishProfile=FolderPublish.pubxml'
artifacts:
paths:
- '.\ApplicationTemplate\bin\Release\Publish\'
Run Code Online (Sandbox Code Playgroud)
输出显示这可以很好地构建代码,并且似乎也成功找到了要上传的工件。但是,当它上传工件时,即使请求得到响应200 OK,该过程也会失败。这是日志输出:
因此,它找到工件,尝试上传它们,甚至获得响应200 OK(与我在网上找到的有关此错误的少数类似报告相反),但由于参数无效,它仍然失败。
我已经启用了详细调试,正如您从输出中看到的那样,但我一无所知。查看托管运行程序的盒子上的 Windows 事件日志中的 GitLab 运行程序条目也无法提供任何信息。工件的总大小为 61.1MB,所以我认为我的问题与此无关。
谁能从这个输出中看出什么是无效的?我可以确定哪个参数无效和/或为什么无效?
artifacts:expire_in …gitlab-ci-runner ×10
gitlab-ci ×9
gitlab ×5
docker ×3
c# ×2
.net ×1
amazon-ec2 ×1
android ×1
deployment ×1
devops ×1
ubuntu-18.04 ×1