Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在bitbucket pipelines.yml文件中写入条件语句?_Javascript_Node.js_Continuous Integration_Bitbucket_Bitbucket Pipelines - Fatal编程技术网

Javascript 如何在bitbucket pipelines.yml文件中写入条件语句?

Javascript 如何在bitbucket pipelines.yml文件中写入条件语句?,javascript,node.js,continuous-integration,bitbucket,bitbucket-pipelines,Javascript,Node.js,Continuous Integration,Bitbucket,Bitbucket Pipelines,我不熟悉bitbucket管道,并尝试使用javaScript通过bitbucket管道部署代码。 我的问题是,我们是否可以声明(ex:var flag=false)这样的变量,然后根据标志值编写if/else语句 下面是我的pipelines.yml文件 # This is a sample build configuration for JavaScript. # Check our guides at https://confluence.atlassian.com/x/14UWN for

我不熟悉bitbucket管道,并尝试使用javaScript通过bitbucket管道部署代码。 我的问题是,我们是否可以声明(ex:var flag=false)这样的变量,然后根据标志值编写if/else语句

下面是我的pipelines.yml文件

# This is a sample build configuration for JavaScript.
# Check our guides at https://confluence.atlassian.com/x/14UWN for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: node:12.18.2

pipelines:
branches: # deploying as per branches
 feature/pocDepTerex: # poc master branch
    - step: 
       caches:
        - node
       script: 
         - node -v
这里,我想声明一个标志,并仅在标志为true时运行脚本节点-v


请让我知道是否有任何方法可以在管道中执行此操作

您当然可以!虽然您可能已经习惯于在bitbucket pipelines.yml中编写一系列单行命令,但您可以使用插入多行内容。例如:

image: node:12.18.2

pipelines:
branches: # deploying as per branches
 feature/pocDepTerex: # poc master branch
    - step: 
       caches:
        - node
       script: 
         - export MY_FLAG=true
         - |
           if [ "$MYFLAG" = true ]; then
             node -v
           fi

全面披露:我为Atlassian工作,但不是Bitbucket Pipelines团队的成员:)

你当然可以!虽然您可能已经习惯于在bitbucket pipelines.yml中编写一系列单行命令,但您可以使用插入多行内容。例如:

image: node:12.18.2

pipelines:
branches: # deploying as per branches
 feature/pocDepTerex: # poc master branch
    - step: 
       caches:
        - node
       script: 
         - export MY_FLAG=true
         - |
           if [ "$MYFLAG" = true ]; then
             node -v
           fi

全面披露:我为Atlassian工作,但不是Bitbucket Pipelines团队的成员:)

嗨,谢谢你的回答。在尝试这种方式时,我遇到了以下错误bash:/opt/atlassian/pipelines/agent/tmp/bashScript7015344215178746479.sh:第5行:意外标记“then”附近的语法错误这可能是我的错误-YAML多行语法建议
使用“折叠”样式,其中新行被解释为空格;或
|
使用“文字”样式,保留换行符。在if/then语句中,换行符或
应在
之后,然后
。我更新了我的答案,给它另一个trynow它给出了以下错误:+export my_FLAG=true-| if[“$MYFLAG”=true];然后是节点-v fi bash:/opt/atlassian/pipelines/agent/tmp/bashscript639217210897659935.sh:第7行:语法错误:文件意外结束。在fi之前似乎缺少一个“-”。当我加上-fi:)谢谢你的帮助嗨,谢谢你的回答。在尝试这种方式时,我遇到了以下错误bash:/opt/atlassian/pipelines/agent/tmp/bashScript7015344215178746479.sh:第5行:意外标记“then”附近的语法错误这可能是我的错误-YAML多行语法建议
使用“折叠”样式,其中新行被解释为空格;或
|
使用“文字”样式,保留换行符。在if/then语句中,换行符或
应在
之后,然后
。我更新了我的答案,给它另一个trynow它给出了以下错误:+export my_FLAG=true-| if[“$MYFLAG”=true];然后是节点-v fi bash:/opt/atlassian/pipelines/agent/tmp/bashscript639217210897659935.sh:第7行:语法错误:文件意外结束。在fi之前似乎缺少一个“-”。我加上-fi:)谢谢你的帮助