Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

105
Visualizações
Github action assign a variable of type env an array of strings

I am having the following problem what you see in the image.

I have a.js file which returns me an array of url strings. Then I should assign this array to an env variable as seen in the example below, but I get the following error.

You can tell me where I'm wrong.

enter image description here

on: 
  workflow_dispatch:
  
name: Test Download Multifile
jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        name: Check out current commit
     
      - name: Url
        run: |
         URL=$(node ./actionMultifile.js)
         echo $URL
         echo "URL=$URL" >> $GITHUB_ENV

actionMultifile.js

async function getData(){
 const url = [
   "https://upload.wikimedia.org/wikipedia/commons/thumb/c/c9/Tyrannosaurus_rex_Sue_at_FMNH.jpg/440px-Tyrannosaurus_rex_Sue_at_FMNH.jpg",
   "https://upload.wikimedia.org/wikipedia/commons/thumb/b/bc/Mosasaurus_beaugei_34.JPG/440px-Mosasaurus_beaugei_34.JPG"
 ]
 return url;
}

getData().then((url) => {
 console.log(url);
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The problem occurs because you need to set the URL env variable using multiline strings

This is because the URL variable here isn't saved like this:

['https://upload.wikimedia.org/wikipedia/commons/thumb/c/c9/Tyrannosaurus_rex_Sue_at_FMNH.jpg/440px-Tyrannosaurus_rex_Sue_at_FMNH.jpg', 'https://upload.wikimedia.org/wikipedia/commons/thumb/b/bc/Mosasaurus_beaugei_34.JPG/440px-Mosasaurus_beaugei_34.JPG']

But like this:

[
'https://upload.wikimedia.org/wikipedia/commons/thumb/c/c9/Tyrannosaurus_rex_Sue_at_FMNH.jpg/440px-Tyrannosaurus_rex_Sue_at_FMNH.jpg',
'https://upload.wikimedia.org/wikipedia/commons/thumb/b/bc/Mosasaurus_beaugei_34.JPG/440px-Mosasaurus_beaugei_34.JPG'
]

Therefore, you workflow should look like this:

    steps:
      - name: Checkout repository content
        uses: actions/checkout@v2 # Checkout the repository content to github runner.

      - name: Setup Node Version
        uses: actions/setup-node@v2
        with:
          node-version: 14 # Install the node version needed

      - name: set multiline env var
        run: |
          echo 'URL<<EOF' >> $GITHUB_ENV
          node ./actionMultifile.js >> $GITHUB_ENV
          echo 'EOF' >> $GITHUB_ENV

Then, be careful, you won't be able to use the ${{ env.URL }} variable directly, otherwise it will only print the first line ([) and break. You need to use it between quotes (").

For example:

      - name: use env var
        run: echo "${{ env.URL }}"

      - name: use env var directly
        run: echo "$URL"

I tested it here if you want to take a look:

  • workflow file
  • workflow run
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda