美文网首页
jenkins配合google doc进行渠道打包

jenkins配合google doc进行渠道打包

作者: tesla1984 | 来源:发表于2018-10-19 15:23 被阅读0次

    前提

    项目中使用walle来进行渠道打包,渠道列表文件在项目中由开发人员维护,但是渠道列表经常变动,所以考虑将渠道列表维护在google doc,这样运营人员就能随时修改

    实现

    Jenkins执行shell脚本,在shell脚本中去更新本地channel.txt文件,然后执行assembleReleaseChannels 方法

    #从google doc上更新channel.txt
    update_channel_file(){
        python_command="python get_channel_from_google.py"
        ${python_command}
    }
    

    get_channel_from_google.py

    第三方库gspread

    import gspread
    from oauth2client.service_account import ServiceAccountCredentials
    
    
    SPREADSHEET_ID = # <Your spreadsheet ID>
    
    def main():
    
        scope = ['https://spreadsheets.google.com/feeds',
                 'https://www.googleapis.com/auth/drive']
    
        credentials = ServiceAccountCredentials.from_json_keyfile_name('credentials.json', scope)
    
    
        gc = gspread.authorize(credentials)
    
        wks = gc.open_by_key(SPREADSHEET_ID).sheet1
    
        row_list = wks.get_all_values()
    
        try:
            with open('./application/channel.txt','w') as f:
                for row in row_list:
                    for cell in row:
                        if cell.strip():
                            print cell
                            f.write(cell)
                            f.write('\n')
        finally:
            if f:
                f.close();
    
    if __name__ == '__main__':
        main()
    

    SPREADSHEET_ID

    image.png

    这个参数就是我们打开google sheet的url里面d后面那块,就是该sheet的唯一id

    credentials.json

    https://gspread.readthedocs.io/en/latest/oauth2.html
    按照该文档操作下来会下载一个json文件到本地,将该参数名字和文件名字保持一致

    ./application/channel.txt

    这个是我主工程里面的walle的渠道列表文件

    相关文章

      网友评论

          本文标题:jenkins配合google doc进行渠道打包

          本文链接:https://www.haomeiwen.com/subject/otoyzftx.html