1. Prepare a Window Server environment, for example, Window Server 2016

  2. Install git git-scm.com/download/wi…

  3. Binary package download address (64 bits) :

Gitlab-runner-downloads.s3.amazonaws.com/latest/bina…

  1. Create a directory, such as: C :\data\gitlab, copy the binary package to this directory and rename it to Gitlab-runner

  2. Open a command line window as administrator and go to the binary package directory

  3. Run the command to register runner

Run the command to register runner

gitlab-runner.exe register
Copy the code

Enter the address and token of the Gitlab server as prompted. This operation is the same as linunx’s. See my other post on how to install and configure gitlab-Runner.

  1. Start GitLab Runner as a service
Exe install gitlab-runner. Exe start Start gitlab-runner. Exe install --user ENTER-YOUR-USERNAME --password ENTER-YOUR-PASSWORD gitlab-runner.exe startCopy the code

The author recommends using the latter, so that the environment variables used by runner startup are consistent with the current user, so that when problems occur in the construction under GitLab, the current account can be directly used to test and check in the Window Server, which is more convenient.

If you use the former, you can also set it directly in the Window service interface, as shown in the figure below

  1. Test the automated build using the.gitlab-ci.yml file

Problems encountered:

  1. Git failed to check out the code and Filename too long was prompted
git config --system core.longpaths true
Copy the code
  1. The bash syntax failed in the. Gitlab-ci. yml script

Gitlab Runner for Window uses Powershell as the command interpreter by default and can modify the config.toml file manually

Change shell to bash as shown below

Note: Add a PATH to bash to the current user’s environment variable PATH and restart the Gitlab Runner service, otherwise bash will not be found

If you have Git installed, bash will be installed, usually in the following directory

  1. Chinese garbled codes appear on the output page of Gitlab Pipeline, as shown in the figure below

Solution: add it to the.gitlab-ci.yml script

 before_script:
    - chcp.com 65001
Copy the code

Example: dotnet_build: stage: build before_script: -chcp.com 65001 script: -dotnet build “web/web.csproj” -c Release

  1. The Web service does not exit if it is started in the built job

If the gitlab Pipeline job is executed directly in the job, the gitlab Pipeline job will hang and cannot exit because the Web application will start the listening service.

Solution: Run the start command start//B "command"The sample start//B "./start.sh"
Copy the code