zoukankan      html  css  js  c++  java
  • 自己开发一个 vsts agent 的 task

    vsts 中支持自定义Build/Release的过程Task

    目标:做一个可以读取 Xamarin.Android 所生成的 APK 的 基本信息的 task ,包括 package(包名) / application label(应用标题 )/version name(版本号)/version code(版本代码)

    下面简述流程

    1.下载并安装 Visual Studio Code(http://code.visualstudio.com ),当然使用 Visual Studio 或者其它任何开发工具也可以

    2.下载并安装最新版本 nodejs(https://nodejs.org),如果是直接安装的 vs 这些应该直接都有了

    3.建立自己的项目文件夹,如 d:codehome

    4.通过 npm 安装编译工具 tfx-cli 

    npm i -g tfx-cli

    5.在自己的项目文件夹中建立一个 vss-extension.json 文件,这个文件中说明了当前扩展包的信息,以及扩展包中包含哪些任务

    {
        "manifestVersion": 1,
        "id": "zou-tasks",
        "name": "Zou Tasks",
        "version": "1.0.4",
        "publisher": "zoujian",
        "targets": [
            {
                "id": "Microsoft.VisualStudio.Services"
            }
        ],
        "description": "Tools for building & publish",
        "categories": [
            "Build and release"
        ],
        "icons": {
            "default": "extension-icon.png"
        },
        "files": [
            {
                "path": "extract-xamarin-android-manifest"
            }
        ],
        "contributions": [
            {
                "id": "extract-xamarin-android-manifest",
                "type": "ms.vss-distributed-task.task",
                "targets": [
                    "ms.vss-distributed-task.tasks"
                ],
                "properties": {
                    "name": "extract-xamarin-android-manifest"
                }
            }
        ]
    }

    6.以上面扩展信息中所示,扩展包中包含了一个叫 extract-xamarin-android-manifest(我的任务) 的插件,文件夹结构是这样的


    extension-icon.png (vsix的图标)
    vss-extension.json

    extract-xamarin-android-manifest
      - extract.ps1 (任务的对应脚本,是在task.json中配置的此名称)
      - icon.png (任务的图标)
      - task.json (任务的配置文件)

    其中 task.json 是最主要的文件,我当前的这个扩展是读取 Xamarin.Android 的项目,并且读取出生成 apk 的基础信息,包含 application 的 label,packagename,version name,version code

    {
      "id": "f1821fab-78d1-4c22-a0e4-f98f40fd7079",//任务的唯一id
      "name": "extract-xamarin-android-manifest",//任务名称
      "friendlyName": "extract xamarin android info",//友好任务名
      "description": "extract xamarin android info",
      "author": "zoujian",
      "helpMarkDown": "[More Information](https://github.com/chsword/zou-vsts-tasks)",//帮助(就是显示时后面的吧号)
      "category": "Utility",//类别,工具
      "visibility": [
        "Build",
        "Release"
      ],
      "demands": [
        "DotNetFramework"
      ],
      "version": {//版本
        "Major": "1",
        "Minor": "0",
        "Patch": "4"
      },
      "minimumAgentVersion": "1.83.0",//支持vso agent的版本
      "instanceNameFormat": "ExtractXamarinAndroidManifest",//实例名
      "groups": [//如果输入参数要分组的话,建一个
        {
          "name": "output",
          "displayName": "Output",
          "isExpanded": true
        }
      ],
      "inputs": [//各种输入参数
        {
          "name": "pathXamarinAndroidProject",
          "type": "filePath",
          "label": "Xamarin Android project Path",
          "defaultValue": "",
          "required": true,
          "helpMarkDown": "Path which Xamarin Android project exisis."
        },
        {
          "name": "configuration",
          "type": "string",
          "label": "Configuration",
          "defaultValue": "$(BuildConfiguration)",
          "required": true
        },
        {
          "name": "outputVariable",
          "type": "string",
          "label": "outputVariable",
          "required": true,
          "defaultValue": "android",
          "groupName": "output",
          "helpMarkDown": "Provide a name for the variable for the android info. eg. set the outputVariable 'android', after task running, will return 'android.PackageName','android.ApplicationLabel','android.VersionName','android.VersionCode'."
        }
      ],
      "execution": {//实际执行的过程,我这里是执行了一个powershell脚本,有兴趣的同学可以看下,就是读取了apk的AndroidManifest的xml结构
        "PowerShell": {
          "target": "$(currentDirectory)\extract.ps1",
          "argumentFormat": "",
          "workingDirectory": "$(currentDirectory)"
        }
      }
    }

    7.要编译为VSIX的话,执行 tfx extension create --manifest-globs vss-extension.json

    8.tfs或vso中导入vsix,过程不说述

    9.可以直接在tfs中使用了

    实际使用时,如此配置参数:

    源代码:https://github.com/chsword/zou-vsts-tasks

    引用 :

    官方task:https://github.com/Microsoft/vsts-tasks

    官方文档:https://www.visualstudio.com/zh-cn/docs/build/define/variables

  • 相关阅读:
    ssm复习资料
    嵌入式开发实践的第二种柱状图代码
    嵌入式开发实践的简单登录代码
    嵌入式开发实践的柱状图代码
    学习ps的坑
    js的执行上下文
    js的渲染
    vue 使用Ueditor富文本的配置
    使用iview Upload进行多文件上传,编辑页初始已上传的图片失败的问题
    beforeEach钩子,next('/login') 跳转问题,无线循环导致Maximum call stack size exceeded问题
  • 原文地址:https://www.cnblogs.com/chsword/p/zou-vsts-tasks-for-xamarin-android.html
Copyright © 2011-2022 走看看