首页 > 解决方案 > GitHub Action to trigger 无法连接詹金斯

问题描述

我正在尝试使用以下工作流文件通过 GitHub Action 触发 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 Action 因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

我在这里想念什么?

标签: jenkinsgithub-actionsbuilding-github-actions

解决方案


报错说明你在 Jenkins 域中有错误:http://jenkins.example.net:8080/ 换成 正确的域

错误消息:“socket.gaierror: [Errno -2] Name or service not known”表示您的程序无法连接到此域,因为它不存在或 DNS 无法解析


推荐阅读