pycontribs / jenkinsapi

A Python API for accessing resources and configuring Hudson & Jenkins continuous-integration servers
http://pypi.python.org/pypi/jenkinsapi
MIT License
857 stars 485 forks source link

Error to create credential with type 'Username with password' #790

Open gaoyanyu opened 4 years ago

gaoyanyu commented 4 years ago
ISSUE TYPE
Jenkinsapi VERSION

0.3.11

Jenkins VERSION

Jenkins ver. 2.204.5

SUMMARY

when I create username/password type credential, just to initialize class Credentials which is in jenkinsapi/credentials.py, it throw out "AttributeError: 'list' object has no attribute 'items'".

EXPECTED RESULTS

create credential success.

ACTUAL RESULTS

fail to create it

USEFUL INFORMATION
    from jenkinsapi.credential import UsernamePasswordCredential
    import uuid
    from jenkinsapi.jenkins import Jenkins
    from jenkinsapi.credentials import Credentials

    jenkins_baseurl = 'http://localhost:8000/'
    creden_baseurl = 'http://localhost:8000/credentials/store/system/domain/_/'
    user = 'admin'
    passwd = 'd8a82b5411f145e59bedac1157885139'
    credential_id = str(uuid.uuid4())
    cred_dict = {'credential_id': credential_id,
                 'fullName': 'test',
                 'typeName': 'Username with password',
                 'displayName': '%s/%s' % (user, passwd),
                 'userName': user,
                 'password': passwd,
                 'description': credential_id}

    jenkins_obj = Jenkins(jenkins_baseurl, username=user, password=passwd)
    credens = Credentials(creden_baseurl, jenkins_obj)
gaoyanyu commented 4 years ago

run result is below: File "/root/PycharmProjects/test/test.py", line 52, in create_repo_credential_in_jenkins credens = Credentials(creden_baseurl, jenkins_obj) File "/root/PycharmProjects/test/venv/lib/python3.7/site-packages/jenkinsapi/credentials.py", line 30, in init JenkinsBase.init(self, baseurl) File "/root/PycharmProjects/test/venv/lib/python3.7/site-packages/jenkinsapi/jenkinsbase.py", line 38, in init self.poll() File "/root/PycharmProjects/test/venv/lib/python3.7/site-packages/jenkinsapi/jenkinsbase.py", line 60, in poll data = self._poll(tree=tree) File "/root/PycharmProjects/test/venv/lib/python3.7/site-packages/jenkinsapi/credentials.py", line 38, in _poll for cred_id, cred_dict in credentials.items(): AttributeError: 'list' object has no attribute 'items'

and I got the parameter credentials in my run process: 'credentials': [{'description': 'test for jenkins', 'displayName': '123root/** (test for jenkins)', 'fingerprint': None, 'fullName': 'system//dockerhub', 'id': 'dockerhub', 'typeName': 'Username with password'}, {'description': 'test for jenkins', 'displayName': '123root/** (test for jenkins)', 'fingerprint': None, 'fullName': 'system//dockerhub1', 'id': 'dockerhub1', 'typeName': 'Username with password'}, {'description': 'test for jenkins', 'displayName': '123root/** (test for jenkins)', 'fingerprint': None, 'fullName': 'system/_/dockerhub2', 'id': 'dockerhub2', 'typeName': 'Username with password'}]

parameter credentials is located in jenkinsapi/credentials.py, class Credentials's _poll function, which looks like below:

`def _poll(self, tree=None): url = self.python_api_url(self.baseurl) + '?depth=2' data = self.get_data(url, tree=tree) credentials = data['credentials'] for cred_id, cred_dict in credentials.items(): cred_dict['credential_id'] = cred_id credentials[cred_id] = self._make_credential(cred_dict)

    return data`
gaoyanyu commented 4 years ago

Anyone meet this situation? please...