Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

106
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda