Python enables Scan Job configuration automation

Source: Internet
Author: User
Tags checkstyle

Continuous integration platform Access Scan Job is a tedious and meticulous work, so in the leisure time, the code scan Job with Python code to achieve the configuration automation.

Each time the job is configured, a corresponding folder is created in the E:\jenkins\workspace\CHECKSTYLE directory on Checkcode1 or CHECKCODE3. Put the Build.xml file in and replace the job name in the canonical scan security Script 3 times. This process is often mistaken, or forgotten.

However, with the following script, everything is not a problem.

First Look at the flowchart:

The Python code is as follows:

1 #!usr/bin/python2 #-*-coding:utf-8-*-3 #Filename:auto.py4 5 ImportOS6 7 Print('Please enter the job name (the default "_code" end, no need to enter _code):')8Input_user=input ()9 Print('Are you sure? (y/n)')Tencommit =input () One   A  while0==len (Input_user)or(commit!='y'  andcommit!='Y'): -     Print('Please enter the job name (the default "_code" end, no need to enter _code):') -Input_user=input () the     Print('Are you sure? (y/n)') -commit =input () - #Piling, output job name - Print('the job name you entered is:%s'%(input_user)) +  - #prepare the appropriate resources +jobname=input_user+'_code' AJobname_upper=Jobname.upper () atJobname_lower=Jobname.lower () -  - #If the file directory does not exist, create a file directory -Dest_dir='E:'+os.sep+'Jenkins'+os.sep+'Workspace'+os.sep+'CHECKSTYLE'+os.sep+Input_user.lower () - if  notos.path.exists (dest_dir): - os.makedirs (Dest_dir) in     Print('successfully created directory%s'%(Dest_dir)) - Else: to     Print('directory%s already exists and can be manipulated directly'%(Dest_dir)) +      - #stitching strings. Note: The actual concatenation of strings is more complicated than this, simplified here just for demonstration convenience.  thestr_1='<xml>\n' *Str_2='\t<djfldfl>'+jobname_upper+'</djfldfl>\n' $str_3='\t<ad>dlfkl</ad>\n'Panax Notoginsengstr_4='</xml>\n' -list=[Str_1,str_2,str_3,str_4] the  + #Write to File Af = Open (dest_dir+os.sep+'Build.xml','W') the f.writelines (list) + Print('Write Build.xml Complete') -F.close ()
Python code

Save the above file in the C:\zzPythonTest directory with the file name "auto.py".

With the above steps, it is not convenient, but also to enter the console for the interpretation of the Python program run, which can be completely replaced by batch processing.

The contents of the batch file are as follows:

@echo off CD c: \Zzpythontestpython Auto. py Pause
Batch File

Then each time only need to click on the Auto.bat file to achieve the effect ~

Check the E-drive, and sure enough, the E:\jenkins\workspace\CHECKSTYLE directory is established:

Open the Build.xml file, and sure enough to achieve the desired effect:

Summarize:

    1. The decision algorithm for fault tolerance has been adjusted for a long time before it is transferred to this more reasonable structure. Confirmation is a very necessary step, because "the wise man cares, there must be a loss."
    2. When creating multi-level catalogs, the way to create a directory is to iterate, and later query to a concise and powerful API, which is makedirs ().
    3. This feature can be implemented in Java, but the advantage of Python is that it is simple and powerful. If you use Java to implement such a function, Java code is almost twice times more than Python.
    4. This feature takes advantage of only the most basic knowledge in Python, and does not even use classes and objects. This is because Python is dealing with the process here, so it does not use OO writing (in fact, the author of the C language of nostalgia, after all, C is the first computer language I contacted).

Python enables Scan Job configuration automation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.