3

I am trying to trigger jenkins build with GitHub Action using following workflow file

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'}"

But Github Action fails for Triggering Jenkins Build [ Backend ] with following error

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'))

During the build running I can see step sohelamin/aws-security-group-add-ip-action@master adds IP to security group and removes at the end.

Why it tries to connect on port=80 instead of port=8080

What I am missing here ?

roy
  • 6,344
  • 24
  • 92
  • 174

2 Answers2

2

The error shows that you are wrong in Jenkin domain: http://jenkins.example.net:8080/ Replace it with your correct domain

Error message: "socket.gaierror: [Errno -2] Name or service not known" mean your program cannot make a connection to this domain because it does not exist or DNS can not resolve

phapli
  • 627
  • 6
  • 16
  • `jenkins.example.net` is just to avoid actual domain on stackoverflow. I do have actual Jenkins URL in the place. – roy Jul 02 '21 at 13:22
1

checking action source reveals that it constructs URL merely by glueing 'http://' to it [1]

try remove 'http://' of your action parameters, e.g. run with

JENKINS_HOST: jenkins.example.net:8080/

instead of

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


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

UPDATE: error stack is easily reproduced, so I guess, url format is the real cause.

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

gives :

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'))
shomeax
  • 855
  • 6
  • 12