【Python】从Jenkins下载最近一次成功构建的安装包

论坛 期权论坛     
选择匿名的用户   2021-6-2 16:06   760   0
<div class="content-detail markdown-body">
<pre class="blockcode"><span style="color:#75715e;">#-*- coding:utf-8 -*-<br></span><span style="color:#66d9ef;font-style:italic;">from </span>case.beatles.test_beatles <span style="color:#66d9ef;font-style:italic;">import </span>TestBeatles<br><span style="color:#66d9ef;font-style:italic;">from </span>framework.logger <span style="color:#66d9ef;font-style:italic;">import </span>Logger<br><span style="color:#66d9ef;font-style:italic;">from </span>page.ios.beatles.jenkins_page <span style="color:#66d9ef;font-style:italic;">import </span>Jenkins_Tool<br><br><span style="color:#66d9ef;font-style:italic;">class </span><span style="color:#a6e22e;">DownloadApp</span>(TestBeatles)<span style="color:#f92672;">:<br></span><span style="color:#f92672;"><br></span><span style="color:#f92672;">   </span><span style="color:#66d9ef;font-style:italic;">def </span><span style="color:#a6e22e;">testDownloadfromJenkins</span>(<span style="color:#94558d;">self</span>)<span style="color:#f92672;">:<br></span><span style="color:#f92672;">      </span><span style="color:#66d9ef;font-style:italic;">try</span><span style="color:#f92672;">:<br></span><span style="color:#f92672;">         </span>jp <span style="color:#f92672;">&#61; </span><span style="color:#66d9ef;">Jenkins_Tool</span>()<br>
jp.<span style="color:#66d9ef;">download_app_from_jenkins</span>()<br><span style="color:#66d9ef;font-style:italic;">except </span><span style="color:#66d9ef;">Exception</span><span style="color:#cc7832;">, </span>e<span style="color:#f92672;">:<br></span><span style="color:#f92672;">         </span>Logger.<span style="color:#66d9ef;">error</span>(e)<br><span style="color:#94558d;">self</span>.<span style="color:#66d9ef;">save_screenshot</span>()<br><span style="color:#94558d;">self</span>.<span style="color:#66d9ef;">fail</span>(e.message)</pre>
<p><br></p>
<p><br></p>
<pre class="blockcode"><span style="color:#75715e;">#-*- coding:utf-8 -*-<br></span><span style="color:#66d9ef;font-style:italic;">from </span>datetime <span style="color:#66d9ef;font-style:italic;">import </span>datetime<br><span style="color:#66d9ef;font-style:italic;">import </span>urllib<br><span style="color:#66d9ef;font-style:italic;">import </span>jenkins<br><span style="color:#66d9ef;font-style:italic;">import </span>os<br><br>
job_names <span style="color:#f92672;">&#61; </span>[<span style="color:#a5c261;">&#39;job-ios&#39;</span><span style="color:#cc7832;">,</span><span style="color:#a5c261;">&#39;job_android&#39;</span>]<br>
username <span style="color:#f92672;">&#61; </span><span style="color:#a5c261;">&#39;Jenkins用户名&#39;<br></span>password <span style="color:#f92672;">&#61; </span><span style="color:#a5c261;">&#39;Jenkins密码&#39;<br></span>base_ios_debug_download_url <span style="color:#f92672;">&#61; </span><span style="color:#a5c261;">&#39;https://xxx/ios/Debug/&#39;<br></span>base_android_debug_download_url <span style="color:#f92672;">&#61; </span><span style="color:#a5c261;">&#39;https://xxx/android/Debug/&#39;<br></span>ios_app_suffix <span style="color:#f92672;">&#61; </span><span style="color:#a5c261;">&#39;.ipa&#39;<br></span><span style="color:#a5c261;"><br></span><span style="color:#66d9ef;font-style:italic;">class </span><span style="color:#a6e22e;">Jenkins_Tool</span>()<span style="color:#f92672;">:<br></span><span style="color:#f92672;">   <br></span><span style="color:#f92672;">   </span><span style="color:#66d9ef;font-style:italic;">def __init__</span>(<span style="color:#94558d;">self</span>)<span style="color:#f92672;">:<br></span><span style="color:#f92672;">      </span><span style="color:#94558d;">self</span>.jenkins_url <span style="color:#f92672;">&#61; </span><span style="color:#a5c261;">&#39;http://jenkins host url&#39;<br></span><span style="color:#a5c261;">      </span><span style="color:#94558d;">self</span>.sever <span style="color:#f92672;">&#61; </span>jenkins.<span style="color:#66d9ef;">Jenkins</span>(<span style="color:#94558d;">self</span>.jenkins_url<span style="color:#cc7832;">, </span><span style="color:#aa4926;">username</span><span style="color:#f92672;">&#61;</span>username<span style="color:#cc7832;">, </span><span style="color:#aa4926;">password</span><span style="color:#f92672;">&#61;</span>password)<br><br><span style="color:#75715e;"># 获取最新构建号<br></span><span style="color:#75715e;">   </span><span style="color:#66d9ef;font-style:italic;">def </span><span style="color:#a6e22e;">get_build_number</span>(<span style="color:#94558d;">self</span><span style="color:#cc7832;">, </span><span style="color:#fd971f;font-style:italic;">job_name</span>)<span style="color:#f92672;">:<br></span><span style="color:#f92672;">      </span>lastest_completed_build_number <span style="color:#f92672;">&#61; </span><span style="color:#94558d;">self</span>.sever.<span style="color:#66d9ef;">get_job_info</span>(<span style="color:#fd971f;font-style:italic;">job_name</span>)[<span style="color:#a5c261;">&#39;lastCompletedBuild&#39;</span>][<span style="color:#a5c261;">&#39;number&#39;</span>]<br><span style="color:#75715e;"># print(lastest_completed_build_number)<br></span><span style="color:#75715e;">      </span><span style="color:#66d9ef;font-style:italic;">return </span>lastest_completed_build_number<br><br><span style="color:#75715e;"># 获取Jenkins下的所有job<br></span><span style="color:#75715e;">   </span><span style
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP