momo's Blog.

gitlab-runner使用笔记

字数统计: 103阅读时长: 1 min
2021/12/14 Share

前言

runner中使用ssh

下方例子:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
image: ubuntu:latest
default:
before_script:
- 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
after_script:
- 'echo {''"''userName''"'': ''"''${GITLAB_USER_NAME}''"'', ''"''jobName''"'': ''"''${XXX_textinput}''"'', ''"''CI_PIPELINE_CREATED_AT''"'': ''"''${CI_PIPELINE_CREATED_AT}''"'', ''"''CI_JOB_STATUS''"'': ''"''${CI_JOB_STATUS}''"'', ''"''CI_JOB_URL''"'': ''"''${CI_JOB_URL}''"''} > tmp.json'
- 'curl -d @tmp.json https://hooks.slack.com/'

run_job:
stage: build
tags:
- ops
script:
- ssh -o StrictHostKeyChecking=no ${XXX_select} "echo 123"
rules:
- if: '$XXX_textinput'
CATALOG
  1. 1. 前言
  2. 2. runner中使用ssh