GitHub 触发操作无法连接 jenkins

GitHub Action to trigger fails to connect jenkins

我正在尝试使用以下工作流文件

通过GitHub操作触发 jenkins 构建
name: Trigger Jenkins Build [ Backend ]
on:
  pull_request:
    branches: [ master ]
    types: [ closed ]
env:
  JENKINS_HOST: "http://jenkins.example.net:8080/"
  JENKINS_JOB: "job/Backend/"
  JENKINS_SECURITY_GROUP_ID: "sg-#####"
jobs:
  trigger:
    name: Triggering Jenkins Build
    runs-on: ubuntu-latest
    steps:
    - name: Add public IP to AWS security group
      uses: sohelamin/aws-security-group-add-ip-action@master
      with:
        aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
        aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        aws-region: 'us-west-2'
        aws-security-group-id: ${{ env.JENKINS_SECURITY_GROUP_ID }}
        port: '8080'
        to-port: ''
        protocol: 'tcp'
        description: 'GitHub Action'
    - name: Triggering Jenkins Build [ Backend ]
      if: github.event.pull_request.merged == true
      uses: GoldenspearLLC/build-jenkins-job@master
      with:
        jenkins-url: ${{ env.JENKINS_HOST }}
        user: ${{ secrets.JENKINS_USER }}
        jenkins-token: ${{ secrets.JENKINS_USER_TOKEN }}
        job-path: ${{ env.JENKINS_JOB }}
        job-params: "{'FRESH_BUILD':'True', 'BUILD_BRANCH':'master', 'DEPLOY_DEV':'True', 'DEPLOY_QA':'False, 'DEPLOY_STAGING':'False, 'DEPLOY_PRODUCTION':'False'}"

但是 Github Triggering Jenkins Build [ Backend ] 的操作失败并出现以下错误

Run GoldenspearLLC/build-jenkins-job@master
  with:
    jenkins-url: http://jenkins.example.net:8080/
    user: ***
    jenkins-token: ***
    job-path: job/Backend/
    job-params: {'FRESH_BUILD':'True', 'BUILD_BRANCH':'master', 'DEPLOY_DEV':'True', 'DEPLOY_QA':'False, 'DEPLOY_STAGING':'False, 'DEPLOY_PRODUCTION':'False'}
  env:
    JENKINS_HOST: http://jenkins.example.net:8080/
    JENKINS_JOB: job/Backend/
    JENKINS_SECURITY_GROUP_ID: sg-####
/usr/bin/docker run --name a33c1e344d347fc1c49778e11b0ded4abedc6_771244 --label 8a33c1 --workdir /***/workspace --rm -e JENKINS_HOST -e JENKINS_JOB -e JENKINS_SECURITY_GROUP_ID -e INPUT_JENKINS-URL -e INPUT_USER -e INPUT_JENKINS-TOKEN -e INPUT_JOB-PATH -e INPUT_JOB-PARAMS -e HOME -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_RETENTION_DAYS -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_SERVER_URL -e GITHUB_API_URL -e GITHUB_GRAPHQL_URL -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e GITHUB_ACTION_REPOSITORY -e GITHUB_ACTION_REF -e GITHUB_PATH -e GITHUB_ENV -e RUNNER_OS -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_***_home":"/***/home" -v "/home/runner/work/_temp/_***_workflow":"/***/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/***/file_commands" -v "/home/runner/work/Backend/Backend":"/***/workspace" 8a33c1:e344d347fc1c49778e11b0ded4abedc6  "http://jenkins.example.net:8080/" "***" "***" "job/Backend/" "{'FRESH_BUILD':'True', 'BUILD_BRANCH':'master', 'DEPLOY_DEV':'True', 'DEPLOY_QA':'False, 'DEPLOY_STAGING':'False, 'DEPLOY_PRODUCTION':'False'}"
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 159, in _new_conn
    conn = connection.create_connection(
  File "/usr/local/lib/python3.8/site-packages/urllib3/util/connection.py", line 61, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/usr/local/lib/python3.8/socket.py", line 918, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 670, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 392, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/local/lib/python3.8/http/client.py", line 1252, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/lib/python3.8/http/client.py", line 1298, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.8/http/client.py", line 1247, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.8/http/client.py", line 1007, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.8/http/client.py", line 947, in send
    self.connect()
  File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 187, in connect
    conn = self._new_conn()
  File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 171, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f773f7fc5b0>: Failed to establish a new connection: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 726, in urlopen
    retries = retries.increment(
  File "/usr/local/lib/python3.8/site-packages/urllib3/util/retry.py", line 446, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='http', port=80): Max retries exceeded with url: /jenkins.example.net:8080/crumbIssuer/api/json (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f773f7fc5b0>: Failed to establish a new connection: [Errno -2] Name or service not known'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/entrypoint.py", line 29, in <module>
    user = server.get_whoami()
  File "/usr/local/lib/python3.8/site-packages/jenkins/__init__.py", line 793, in get_whoami
    response = self.jenkins_open(requests.Request(
  File "/usr/local/lib/python3.8/site-packages/jenkins/__init__.py", line 557, in jenkins_open
    return self.jenkins_request(req, add_crumb, resolve_auth).text
  File "/usr/local/lib/python3.8/site-packages/jenkins/__init__.py", line 573, in jenkins_request
    self.maybe_add_crumb(req)
  File "/usr/local/lib/python3.8/site-packages/jenkins/__init__.py", line 370, in maybe_add_crumb
    response = self.jenkins_open(requests.Request(
  File "/usr/local/lib/python3.8/site-packages/jenkins/__init__.py", line 557, in jenkins_open
    return self.jenkins_request(req, add_crumb, resolve_auth).text
  File "/usr/local/lib/python3.8/site-packages/jenkins/__init__.py", line 576, in jenkins_request
    self._request(req))
  File "/usr/local/lib/python3.8/site-packages/jenkins/__init__.py", line 550, in _request
    return self._session.send(r, **_settings)
  File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='http', port=80): Max retries exceeded with url: /jenkins.example.net:8080/crumbIssuer/api/json (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f773f7fc5b0>: Failed to establish a new connection: [Errno -2] Name or service not known'))

在构建过程中 运行 我可以看到步骤 sohelamin/aws-security-group-add-ip-action@master 将 IP 添加到安全组并在最后删除。

为什么它尝试连接 port=80 而不是 port=8080

我在这里缺少什么?

报错说明你在Jenkin域中错误:http://jenkins.example.net:8080/ 将其替换为您正确的域

错误消息:“socket.gaierror: [Errno -2] 名称或服务未知”表示您的程序无法连接到该域,因为它不存在或 DNS 无法解析

检查动作源显示它仅通过将 'http://' 粘附到 [1]

来构造 URL

尝试删除 'http://' 的操作参数,例如运行 和

JENKINS_HOST: jenkins.example.net:8080/

而不是

JENKINS_HOST: http://jenkins.example.net:8080/


[1] - https://github.com/GoldenspearLLC/build-jenkins-job/blob/master/entrypoint.py#L28

更新:错误堆栈很容易重现,所以我想,url 格式才是真正的原因。

import requests
sess = requests.Session()
r = sess.prepare_request(requests.Request('GET', 'https://https://www.google.com/'))
sess.send(r)

给出:

Traceback (most recent call last):
  File "/Users/m.shonichev/src/venv/lib/python3.9/site-packages/urllib3/connection.py", line 169, in _new_conn
    conn = connection.create_connection(
  File "/Users/m.shonichev/src/venv/lib/python3.9/site-packages/urllib3/util/connection.py", line 73, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/usr/local/Cellar/python@3.9/3.9.2_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/socket.py", line 953, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/Users/m.shonichev/src/venv/lib/python3.9/site-packages/urllib3/connectionpool.py", line 699, in urlopen
    httplib_response = self._make_request(
  File "/Users/m.shonichev/src/venv/lib/python3.9/site-packages/urllib3/connectionpool.py", line 382, in _make_request
    self._validate_conn(conn)
  File "/Users/m.shonichev/src/venv/lib/python3.9/site-packages/urllib3/connectionpool.py", line 1010, in _validate_conn
    conn.connect()
  File "/Users/m.shonichev/src/venv/lib/python3.9/site-packages/urllib3/connection.py", line 353, in connect
    conn = self._new_conn()
  File "/Users/m.shonichev/src/venv/lib/python3.9/site-packages/urllib3/connection.py", line 181, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x10e1ce340>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/Users/m.shonichev/src/venv/lib/python3.9/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/Users/m.shonichev/src/venv/lib/python3.9/site-packages/urllib3/connectionpool.py", line 755, in urlopen
    retries = retries.increment(
  File "/Users/m.shonichev/src/venv/lib/python3.9/site-packages/urllib3/util/retry.py", line 574, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='http', port=443): Max retries exceeded with url: //www.google.com/ (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x10e1ce340>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Users/m.shonichev/src/venv/lib/python3.9/site-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "/Users/m.shonichev/src/venv/lib/python3.9/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='http', port=443): Max retries exceeded with url: //www.google.com/ (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x10e1ce340>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known'))