Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
431 views
in Technique[技术] by (71.8m points)

javascript - 如何在Azure生成管道中打包JS应用并将其保存在单独的C#存储库中(How to package JS app in Azure Build Pipeline and Save in Separate C# Respository)

TL;DR - Using two separate repositories (because that's how I've inherited them) I'm attempting to run a custom script to build a JS-only app that is then copied and deployed along with a C# API app that's housed in a second respository.

(TL; DR-使用两个单独的存储库(因为这是我继承它们的方式),我试图运行一个自定义脚本来构建仅JS的应用程序,然后将其复制和部署,并将其与C#API应用程序一起放置在第二个存储库。)

Using Azure DevOps Services (cloud-based) for repos and pipelines.

(将Azure DevOps Services(基于云)用于存储库和管道。)

As I've indicated above I'm working my way through the process of running these scripts to create a single .js file that's ready to be deployed with our API (the JS app is called and created by a variety of our applications using this API).

(如上文所述,我正在逐步运行这些脚本,以创建一个单一的.js文件,该文件已准备好与我们的API一起部署(JS应用程序已由许多应用程序使用此API调用和创建) API)。)

My conundrum is how to approach this using Azure's Build Pipe as I can run the scripts but where the file(s) created are then being stored (and where to reference them) and then taking that file and inserting this creation into the repository of the C# API app, thereby kicking off a second build that would then deploy the C# app to the appropriate service.

(我的难题是如何使用Azure的构建管道来解决此问题,因为我可以运行脚本,但是将创建的文件存储到哪里(以及在何处引用它们),然后获取该文件并将此创建内容插入到该文件的存储库中。 C#API应用程序,从而启动第二个构建,然后再将C#应用程序部署到适当的服务。)

In another JS project I've successfully copied the files in my build pipes to then push these 'builds' to the appropriate environments but I'm at a loss for copying a specific file, following the npm run build-prod step to save and then insert a file in a known static location to the second repository.

(在另一个JS项目中,我已经成功复制了构建管道中的文件,然后将这些“构建”推送到适当的环境,但是在npm run build-prod步骤保存并保存之后,我对于复制特定文件不知所措。然后将文件插入第二个存储库的已知静态位置。)

NOTE: both repositories are located in the same organization.

(注意:两个存储库都位于同一组织中。)

Here's my uber rough draft YAML for the JS application:

(这是我针对JS应用程序的超级粗略YAML草案:)


trigger:
- master

pool:
  vmImage: 'vs2017-win2016'

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '10.x'
  displayName: 'Install Node.js'

- script: |
    npm install
    npm run build-prod
  displayName: 'npm install and build-prod'

- task: CopyFiles@2
  inputs:
    SourceFolder: '$(agent.builddirectory)/dist/'
    Contents: '**'
    TargetFolder: '$(build.artifactstagingdirectory)'

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)/closet-api.js'
    ArtifactName: 'closet-api.js'
    publishLocation: 'Container'

Your help is appreciated!

(感谢您的帮助!)

  ask by Austin DeLaRosa translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think you need to do is to transform your data from object not to JSON string, but to url params.

(我认为您需要做的是将数据从对象转换为JSON参数,而不是JSON字符串。)

From Ben Nadel's blog .

(来自Ben Nadel的博客 。)

By default, the $http service will transform the outgoing request by serializing the data as JSON and then posting it with the content- type, "application/json".

(默认情况下,$ http服务将通过将数据序列化为JSON并将其发布为内容类型“ application / json”来转换传出请求。)

When we want to post the value as a FORM post, we need to change the serialization algorithm and post the data with the content-type, "application/x-www-form-urlencoded".

(当我们想将值发布为FORM时,我们需要更改序列化算法,并使用内容类型“ application / x-www-form-urlencoded”来发布数据。)

Example from here .

(这里的例子。)

$http({
    method: 'POST',
    url: url,
    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
    transformRequest: function(obj) {
        var str = [];
        for(var p in obj)
        str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
        return str.join("&");
    },
    data: {username: $scope.userName, password: $scope.password}
}).then(function () {});

UPDATE(更新)

To use new services added with AngularJS V1.4, see

(要使用AngularJS V1.4中添加的新服务,请参阅)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...