File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/jenkinsmod.cpython-310.pyc
Back
o ;j�. � @ s d Z ddlZddlZddlZddlmZmZ zddlZdZ W n e y) dZ Y nw e�e�Z dZdd� Zd d � Zdd� Zd d� Zdd� Zdd� Zd*dd�Zd*dd�Zd+dd�Zd,dd�Zd,dd�Zd*dd�Zd*d d!�Zd*d"d#�Zd*d$d%�Zd*d&d'�Zd(d)� ZdS )-a= Module for controlling Jenkins :depends: python-jenkins .. versionadded:: 2016.3.0 :depends: python-jenkins_ Python module (not to be confused with jenkins_) .. _python-jenkins: https://pypi.python.org/pypi/python-jenkins .. _jenkins: https://pypi.python.org/pypi/jenkins :configuration: This module can be used by either passing an api key and version directly or by specifying both in a configuration profile in the salt master/minion config. For example: .. code-block:: yaml jenkins: api_key: peWcBiMOS9HrZG15peWcBiMOS9HrZG15 � N)�CommandExecutionError�SaltInvocationErrorTF�jenkinsc C s t rttd�r tS dS dS )zZ Return virtual name of the module. :return: The virtual name of the module. �Jenkins)FztThe wrong Python module appears to be installed. Please make sure that 'python-jenkins' is installed, not 'jenkins'.)FzOThe jenkins execution module cannot be loaded: python-jenkins is not installed.)�HAS_JENKINS�hasattrr �__virtualname__� r r �K/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/jenkinsmod.py�__virtual__0 s r c C s� t d d�pt d d�pt d d�} t d d�p#t d d�p#t d d�}t d d�p5t d d�p5t d d�}| s<td ��tj| ||d �S )zw Return server object used to interact with Jenkins. :return: server object used to interact with Jenkins z config.getzjenkins.urlzjenkins:urlz pillar.getzjenkins.userzjenkins:userzjenkins.passwordzjenkins:passwordzNo Jenkins URL found.)�username�password)�__salt__r r r )Zjenkins_urlZjenkins_userZjenkins_passwordr r r �_connectG s( � � � � � ��r c C s$ t d | |�}|std| � ���|S )z� Helper to cache the config XML and raise a CommandExecutionError if we fail to do so. If we successfully cache the file, return the cached path. z cp.cache_filezFailed to retrieve )r r )� config_xml�saltenv�retr r r �_retrieve_config_xmlg s r c C s t � }|�| �S )z� .. versionadded:: 2017.7.0 Execute a script on the jenkins master :param script: The script CLI Example: .. code-block:: bash salt '*' jenkins.run 'Jenkins.instance.doSafeRestart()' )r Z run_script)Zscript�serverr r r �runt s r c C s t � } | �� }|r|S dS )z� Return version of Jenkins :return: The version of Jenkins CLI Example: .. code-block:: bash salt '*' jenkins.get_version F)r �get_version)r �versionr r r r � � r c C s t � } | �� }|r|S i S )z� Return the currently configured jobs. :return: The currently configured jobs. CLI Example: .. code-block:: bash salt '*' jenkins.get_jobs )r �get_jobs)r Zjobsr r r r � r r c C s$ | st d��t� }|�| �rdS dS )a Check whether the job exists in configured Jenkins jobs. :param name: The name of the job is check if it exists. :return: True if job exists, False if job does not exist. CLI Example: .. code-block:: bash salt '*' jenkins.job_exists jobname �$Required parameter 'name' is missingTF)r r � job_exists��namer r r r r � s r c C s@ | st d��t� }t| �std| � d���|�| �}|r|S dS )z� Return information about the Jenkins job. :param name: The name of the job is check if it exists. :return: Information about the Jenkins job. CLI Example: .. code-block:: bash salt '*' jenkins.get_job_info jobname r �Job '�' does not existF�r r r r �get_job_info�r r Zjob_infor r r r! � s r! c C sl | st d��t� }t| �std| � d���z |�| |� W dS tjy5 } z td| � d|� ���d}~ww )a; Initiate a build for the provided job. :param name: The name of the job is check if it exists. :param parameters: Parameters to send to the job. :return: True is successful, otherwise raise an exception. CLI Example: .. code-block:: bash salt '*' jenkins.build_job jobname r r z' does not exist.z Encountered error building job '�': NT)r r r r � build_jobr �JenkinsException)r � parametersr �errr r r r$ � s ���r$ �basec C s� | st d��t| �rtd| � d���|stj}n%t||�}tjj� |��}tjj �|�� �}W d � n1 s8w Y t � }z |�| |� W |S tjy` } z td| � d|� ���d}~ww )a� Return the configuration file. :param name: The name of the job is check if it exists. :param config_xml: The configuration file to use to create the job. :param saltenv: The environment to look for the file in. :return: The configuration file used for the job. CLI Example: .. code-block:: bash salt '*' jenkins.create_job jobname salt '*' jenkins.create_job jobname config_xml='salt://jenkins/config.xml' r r z' already existsNz Encountered error creating job 'r# )r r r r �EMPTY_CONFIG_XMLr �salt�utils�files�fopen�stringutils� to_unicode�readr � create_jobr% �r r r Zconfig_xml_file�_fpr r'