我正在 yaml 中构建一个复杂的管道,并尝试在两个作业之间创建依赖关系,以便后一个作业在前一个作业之后运行,但前提是前者设置为基于参数运行。我似乎无法弄清楚这是否可行。
我有一个这样定义的管道:
parameters:
- name: doJobA
type: boolean
stages:
jobs:
- job: JobA
condition: eq('${{ parameters.doJobA }}', true)
# ... details removed for brevity
- job: JobB
dependsOn: JobA
# ... details removed for brevity
Run Code Online (Sandbox Code Playgroud)
JobB应该在JobAifparameters.doJobA为 true 后运行,或者如果parameters.doJobA为 false 则立即运行。如果不满足条件,简单地添加dependsOn条件就会导致跳过,这是有道理的,但我希望它无论如何都能运行。JobBJobA
dependsOn是否可以以这种方式定义条件?
编辑:我遇到了一个额外的问题,导致下面的解决方案无法使用。我需要条件依赖于先前运行的 PowerShell 脚本设置的变量,而不是基于参数。
我正在尝试使用List.Sort()对对象列表进行排序,但在运行时它告诉我它无法比较数组中的元素.
无法比较数组中的两个元素
班级结构:
public abstract class Parent : IComparable<Parent> {
public string Title;
public Parent(string title){this.Title = title;}
public int CompareTo(Parent other){
return this.Title.CompareTo(other.Title);
}
}
public class Child : Parent {
public Child(string title):base(title){}
}
List<Child> children = GetChildren();
children.Sort(); //Fails with "Failed to compare two elements in the array."
Run Code Online (Sandbox Code Playgroud)
为什么我不能比较实现的基类的子类IComparable<T>?我可能错过了一些东西,但我不明白为什么不允许这样做.
编辑:应该澄清我的目标是.NET 3.5(SharePoint 2010)
Edit2:.NET 3.5是问题(见下面的答案).
我想创建一个通用的“未找到”组件,如果StaticRouter使用它,将 statusCode 设置为 404 。我知道我可以这样做:
<Route
render={(routeComponentProps) => <NotFound {...routeComponentProps} />}
/>
Run Code Online (Sandbox Code Playgroud)
Or use a child function as the doc describes, but as my app is growing in complexity I'd like to simplify it down to the way I specify all my other routes in order to avoid having to remember to pass props to the NotFound component. Something like this:
<Route>
<NotFound />
</Route>
Run Code Online (Sandbox Code Playgroud)
This means I'd like to access staticContext inside <NotFound/> using a hook (preferrably), …
我使用express+ passport+nextjs设置,将使用ID连接进行认证的应用程序。用户数据存储在请求对象上,使用express-session它req.user像往常一样为我提供每个请求。
现在我想将用户信息传递给前端,以便我可以将它用于某些事情,但似乎没有任何一致的方法可以对所有请求执行此操作。我可以getServerSideProps用于单个页面,但不能用于通过_document或 的每个页面_app。我该如何设置?
这是我的当前 _document.tsx
import Document, {
Head,
Main,
NextScript,
DocumentContext,
} from "next/document"
export default class Doc extends Document {
public static async getInitialProps(ctx: DocumentContext) {
const req: any = ctx.req
console.log("req/user", `${!!req}/${!!(req && req.user)}`)
const initialProps = await Document.getInitialProps(ctx)
return {
...initialProps,
user: req?.user || "no user",
}
}
public render() {
return (
<html>
<Head />
<body>
<Main />
<NextScript …Run Code Online (Sandbox Code Playgroud) 我定义了这个 DTO 类。
import { ApiProperty } from "@nestjs/swagger"
export class FormDTO {
@ApiProperty()
id: string
@ApiProperty()
type: string
@ApiProperty()
fieldValues?: Record<string, unknown>
@ApiProperty()
parentFormId?: string
}
Run Code Online (Sandbox Code Playgroud)
我预计生成的 OpenAPI 规范会表明这一点fieldValues并且parentFormId是可选的,但它们是必需的。
根据此处文档中的示例,它们应该是可选的。我缺少什么?
使用该 DTO 的唯一方法如下所示,但我认为这并不重要:
@Post(":id")
createForm(@Body() createFormDto: FormDTO) {
if (this.formService.hasForm(createFormDto.id)) {
throw new ConflictException(
undefined,
`A form with the id ${createFormDto.id} already exists.`
)
}
return this.formService.createOrUpdateForm(createFormDto)
}
Run Code Online (Sandbox Code Playgroud)
如果重要的话,这里是代码DocumentBuilder
const config = new DocumentBuilder()
.setTitle("API")
.setDescription(
"description."
)
.setVersion("1.0")
.addBearerAuth(
{
type: …Run Code Online (Sandbox Code Playgroud) 我试图让 Joi 在另一个引用的辅助模式上强制执行默认值。我有两个像这样的模式:
const schemaA = Joi.object().keys({
title: Joi.string().default(''),
time: Joi.number().min(1).default(5000)
})
const schemaB = Joi.object().keys({
enabled: Joi.bool().default(false),
a: schemaA
})
Run Code Online (Sandbox Code Playgroud)
我想要的是提供一个a未定义的对象,并让 Joi 为其应用默认值,如下所示:
const input = {enabled: true}
const {value} = schemaB.validate(input)
//Expect value to equal this:
const expected = {
enabled: true,
a: {
title: '',
time: 5000
}
}
Run Code Online (Sandbox Code Playgroud)
问题在于,由于密钥是可选的,因此根本没有强制执行。所以我想要的是它是可选的,但schemaA如果不存在则正确填充默认值。我一直在查看文档,但似乎无法找到任何关于此的信息,尽管我可能遗漏了一些明显的内容。有小费吗?
我无法弄清楚它的目的customState以及是否/如何利用它来将数据传递到返回网址。具体来说,我希望在登录后将用户路由回其原始位置。我想我可以将原始 url 传递给参数customState,并在 return url 中将其返回给我POST,但它似乎已被编码或可能被替换为不同的值。
这是我想要实现的目标:
/page/protected需要身份验证。passport.authenticate进而重定向用户进行登录。/auth/oidc/return。/page/protected。是否可以在TypeScript中定义函数类型并将其参数列表扩展为其他类型(重载函数类型?)?
假设我有这种类型:
type BaseFunc = (a: string) => Promise<string>
我想用一个附加参数(b:数字)和相同的返回值定义另一种类型。
如果将来某个时候BaseType添加或更改参数,这也应该反映在我的重载函数类型中。
这可能吗?
我正在使用 Azure DevOps 管道来部署我的代码,现在我需要将变量值从部署作业传递到依赖于它的后续作业。我已经阅读了这个例子,但它似乎根本不起作用。
我想做的是运行一个配置 Key Vault 的 Azure ARM 部署。密钥保管库的名称是从 ARM 部署作业输出的,然后我尝试将该名称传递给另一个需要添加特定机密的作业。访问控制已得到处理,但我仍然需要传递名称。
我已将问题归结为将变量从 a 传递deployment到 a的基础知识job。这是我完整的测试管道(几乎完全从这里复制):
trigger: none
stages:
- stage: X
jobs:
- deployment: A
pool:
vmImage: "ubuntu-16.04"
environment: test
strategy:
runOnce:
deploy:
steps:
- script: echo "##vso[task.setvariable variable=myOutputVar;isOutput=true]this is the deployment variable value"
name: setvarStep
- script: echo $(setvarStep.myOutputVar)
name: echovar
- job: B
dependsOn: A
pool:
vmImage: "ubuntu-16.04"
variables:
myVarFromDeploymentJob: $[ dependencies.A.outputs['deploy.setvarStep.myOutputVar'] ]
steps:
- script: "echo $(myVarFromDeploymentJob)" …Run Code Online (Sandbox Code Playgroud) azure-devops ×2
.net-3.5 ×1
adal ×1
azure-ad-b2c ×1
c# ×1
express ×1
icomparable ×1
javascript ×1
joi ×1
nestjs ×1
next.js ×1
node.js ×1
react-router ×1
reactjs ×1
swagger ×1
typescript ×1