前提
項目中使用walle來進(jìn)行渠道打包,渠道列表文件在項目中由開發(fā)人員維護(hù),但是渠道列表經(jīng)常變動,所以考慮將渠道列表維護(hù)在google doc,這樣運營人員就能隨時修改
實現(xiàn)
Jenkins執(zhí)行shell腳本,在shell腳本中去更新本地channel.txt文件,然后執(zhí)行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
這個參數(shù)就是我們打開google sheet的url里面d后面那塊,就是該sheet的唯一id
credentials.json
https://gspread.readthedocs.io/en/latest/oauth2.html
按照該文檔操作下來會下載一個json文件到本地,將該參數(shù)名字和文件名字保持一致
./application/channel.txt
這個是我主工程里面的walle的渠道列表文件