chmod +x 在 YML Azure Devops 中运行脚本的方法

问题描述 投票:0回答:1

我已经开始练习如何在azure devops中创建yml。我做了以下简单的例子。

azure-pipelines.yml

# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

parameters:
- name: name
  type: string

trigger:
- master

pool:
 vmImage: ubuntu-latest

steps:
- checkout: self
  persistCredentials: true
  fetchTags: true
  clean: true

- task: Bash@3
  displayName: 'Run hello script'
  inputs:
    targetType: 'inline'
    script: |
      chmod +x "./scripts/hello.sh"
      ./scripts/hello.sh  ${{ parameters.name}}
  continueOnError: false

你好.sh

#!/bin/sh

# Parameters
NAME=$1

echo "Hello $NAME, this is a script"

我想知道什么?

添加

chmod +x "./scripts/hello.sh"
是一个好方法吗? 因为当我不添加这个时,我总是得到
"script has no permission"
错误。一旦我用该线运行管道,它就可以正常工作。

我为什么问这个?

我在互联网上研究了很多有关 YML 示例的信息,但我从未看到他们添加了

chmod +x "script_name"
行,所以这就是我对此感到好奇的原因..

azure azure-devops azure-pipelines azure-pipelines-yaml
1个回答
0
投票

从 Azure Pipeline 中的源存储库调用 Bash 脚本文件 (

.sh
) 时,不需要使用命令“
chmod +x
”来分配对脚本文件的访问权限。您可以使用“
filePath
”类型直接在 Bash 任务上调用脚本文件。

parameters:
- name: name
  type: string
  default: 'xxxx'

trigger:
- master

pool:
 vmImage: ubuntu-latest

steps:
- checkout: self
  . . .

- task: Bash@3
  displayName: 'Run hello script'
  inputs:
    targetType: filePath
    filePath: 'scripts/hello.sh'
    arguments: '"${{ parameters.name}}"'
© www.soinside.com 2019 - 2024. All rights reserved.