流水线

作者: 曹赫洋 | 来源:发表于2020-01-03 12:23 被阅读0次

JavaLambdaCI.groovy

def call(body) {
  def config = [:]
  body.resolveStrategy = Closure.DELEGATE_FIRST
  body.delegate = config
  body()
  
  def project = config.project
  
  def jenkins_node = 'master'
 
  pipeline {
    node {
      stage('chekcout source code') {
        checkout scm
      }
      stage('compile') {
        sh('mvn clean package')
      }
      stage('udpate lambda function') {
        def file_path=pwd()
        def update_lambda_code = libraryResource 'update_lambda.py'
        writeFile file: 'update_lambda.py', text: update_lambda_code
        sh('python3 update_lambda.py -lambda_function tiny-url-lambda -file_path '+file_path+'/target/'+project+'-lambda-package.zip -profile global -region us-east-1')
      }
    }
  }
}

update_lambda.py

import boto3, json, os, argparse, zipfile, glob, botocore

def update_lambda(client, function_name, zip_path, profile_name, region):
    """
    更新lambda函数代码
    :param client: boto3连接
    :param function_name:lambda函数名称
    :param zip_path:本机源代码存储路径
    :param profile_name:使用aws-cli配置文件名称
    :param region:aws region
    :return:
    """
    with open(zip_path, 'rb') as zip_blob:
        response = client.update_function_code(
            FunctionName=function_name,
            ZipFile=zip_blob.read()
        )
        print(response)


def main():
    # 更新lambda函数代码
    parser = argparse.ArgumentParser(description='Execute input file. Supports only python or sh file.')
    #lambda函数名称
    parser.add_argument('-lambda_function', '--function_name', required=True, help='Lambda function name')
    #本机源代码存储路径
    parser.add_argument('-file_path', '--zip_path', required=True, help='the path of zip file')
    #使用aws-cli配置文件名称
    parser.add_argument('-profile', '--profile_name', required=True, help='profile name for aws key')
    #aws region
    parser.add_argument('-region', '--region', required=False, help='region name')
    args = parser.parse_args()
    # 获取入参
    function_name = args.function_name
    zip_path = args.zip_path
    profile_name = args.profile_name
    region = args.region

    client = boto3.session.Session(profile_name=profile_name, region_name=region).client('lambda')
    update_lambda(client, function_name, zip_path, profile_name, region)


if __name__ == '__main__':
    main()

DeployWebsiteToS3.groovy

def call(body) {
  def config = [:]
  body.resolveStrategy = Closure.DELEGATE_FIRST
  body.delegate = config
  body()
  
  def project = config.project
  def jenkins_node = 'master'
 
  pipeline {
    node {
      stage('chekcout source code') {
        checkout scm
      }
      stage('deploy website to S3') {
        sh('aws s3 sync . s3://'+project+'/  --profile global --region us-east-1 --delete --exclude ".git/*" --exclude "Jenkinsfile" --exclude "README.md"')
      }
    }
  }
}

相关文章

  • Jenkins之声明式流水线语法

    1 流水线 1.1 简介 jenkins 有 2 种流水线分为声明式流水线与脚本化流水线,脚本化流水线是 jenk...

  • 【计算机体系结构】流水线的认识

    流水线的认识 1.流水线中的每个子过程及其功能部件称为流水线的级或段,段与段相互连接形成流水线。流水线的段数称为流...

  • Unity Shader学习-1.渲染流水线

    Unity Shader学习-1.渲染流水线 先了解一下什么是流水线:(下面是百度百科的定义) 流水线:流水线又称...

  • Unity Shader学习-1.渲染流水线【转】

    Unity Shader学习-1.渲染流水线 先了解一下什么是流水线:(下面是百度百科的定义) 流水线:流水线又称...

  • ECRS工时分析,视与视ECRS工时分析软件论述工业生产方式的发

    经过20多年的实践,日本的电器业已经彻底告别了流水线。从学习流水线,到改造流水线,再到告别流水线,这是一个生产方式...

  • 如何正确选择合适自己公司的流水线设备

    如何选择一台合适流水线设备?合适的流水线设备能有效的提高生产效率,选购流水线设备时,要注意流水线的形式是否符合生产...

  • Pipeline

    Pipeline(流水线):支持两种语法格式-------->声明式,脚本式流水线 声明式 脚本式流水线 TEST...

  • jenkins声明式流水线

    pipeline最简结构 pipeline:代表整条流水线,包含整条流水线的逻辑 agent:指定流水线的执行器 ...

  • 《流水线》舒婷

    在时间的流水线里 夜晚和夜晚紧紧相挨 我们从工厂的流水线撤下 又以流水线的队伍回家来 在我们头顶 星星的流水线拉过...

  • 2019-05-09

    如何让你的企业变成人才生产基地? 你的企业有育人流水线吗? 育人流水线又分为“新人流水线”“老人流水线”“精英干部...

网友评论

      本文标题:流水线

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