[JIRA] (JENKINS-59933) Injected array variables are not available in {bash zxh} shell

22 views
Skip to first unread message

fsteff@gmail.com (JIRA)

unread,
Oct 25, 2019, 8:51:48 AM10/25/19
to jenkinsc...@googlegroups.com
Flemming Steffensen created an issue
 
Jenkins / Bug JENKINS-59933
Injected array variables are not available in {bash zxh} shell
Issue Type: Bug Bug
Assignee: Unassigned
Components: envinject-plugin
Created: 2019-10-25 12:50
Priority: Major Major
Reporter: Flemming Steffensen

Main problem: Injected array variables are not available in shell.

Injecting variable containing arrays such as the below, fails on bash, zxh and other shells.

 

test[0]=string1
test[1]=string2
foo=bar

Attempting to use these imported variables fails like this:

>echo ${test[0]}
>echo ${test[1]}
>echo ${foo}
bar

Normally there are two categories of variables available in shell: shell variables and Environment variables, where shell variables can also be exported to become Environment variables.

However, when testing the output of five commands that can list variables, it seems that injected array variables falls into a third category, as the array variables are available as Environmental variables, but not as shell variables:

  1. `declare -p`, `declare -xp` and `set` lists no injected array variables
  2. `printenv` and `env` lists injected array variables, as individual entries.

 

 

I've implemented workaround, which may be integrated into the plugin, that can be used to fix the main issue. It's available as a gist on github:

https://gist.github.com/f-steff/1181f8f5907ae9da73779aba8182df3b#file-fixinjectedarraysinbash-sh

Using this workaround, the output from my test injection above looks like this:

Attempting to use these imported variables fails like this:

>. ./FixInjectedArraysInBash.sh
>echo ${test[0]}
string1
>echo ${test[1]}
string2
>echo ${foo}
bar

Second related problem.

A warning may be needed when this happens!

When importing/declaring variables like this:

test[0]=string1
test[1]=string2
test=string3

will result in an unintended overwriting of test[0], resulting in an array declared like this: test=([0]="string3" [1]="string2")

 
 

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

fsteff@gmail.com (JIRA)

unread,
Oct 25, 2019, 8:52:06 AM10/25/19
to jenkinsc...@googlegroups.com

fsteff@gmail.com (JIRA)

unread,
Oct 25, 2019, 8:53:03 AM10/25/19
to jenkinsc...@googlegroups.com
Flemming Steffensen updated an issue
Change By: Flemming Steffensen
h1. Main problem: Injected array variables are not available in shell.


Injecting variable containing arrays such as the below, fails on bash, zxh and other shells.

 
{code:java}

test[0]=string1
test[1]=string2
foo=bar
{code}

Attempting to use these imported variables fails like this:
{code:java}

>echo ${test[0]}
>echo ${test[1]}
>echo ${foo}
bar{code}

Normally there are two categories of variables available in shell: shell variables and Environment variables, where shell variables can also be exported to become Environment variables.

However, when testing the output of five commands that can list variables, it seems that injected array variables falls into a third category, as the array variables are available as Environmental variables, but not as shell variables:
# `declare -p`, `declare -xp` and `set` lists no injected array variables
# `printenv` and `env` lists injected array variables, as individual entries.


 

 

I've implemented workaround, which may be integrated into the plugin, that can be used to fix the main issue. It's available as a gist on github:

[https://gist.github.com/f-steff/1181f8f5907ae9da73779aba8182df3b#file-fixinjectedarraysinbash-sh]

Using this workaround, the output from my test injection above looks like this:

Attempting to use these imported variables fails like this:
{code:java}

>. ./FixInjectedArraysInBash.sh
>echo ${test[0]}
string1
>echo ${test[1]}
string2
>echo ${foo}
bar{code}
h1. Second related problem.


A warning may be needed when this happens!

When importing/declaring variables like this:
{code:java}

test[0]=string1
test[1]=string2
test=string3
{code}

will result in an unintended overwriting of {{test[0]}}, resulting in an array declared like this: {{test=([0]="string3" [1]="string2")}}

 
 

fsteff@gmail.com (JIRA)

unread,
Oct 25, 2019, 8:54:02 AM10/25/19
to jenkinsc...@googlegroups.com
Flemming Steffensen updated an issue
h1. Main problem: Injected array variables are not available in shell.

Injecting variable containing arrays such as the below, fails on bash, zxh and other shells.

 
{code:java}
test[0]=string1
test[1]=string2
foo=bar
{code}
Attempting to use these imported variables fails like this:
{code:java}
>echo ${test[0]}
>echo ${test[1]}
>echo ${foo}
bar{code}
Normally there are two categories of variables available in shell: shell variables and Environment variables, where shell variables can also be exported to become Environment variables.

However, when testing the output of five commands that can list variables, it seems that injected array variables falls into a third category, as the array variables are available as Environmental variables, but not as shell variables:
# `declare -p`, `declare -xp` and `set` lists no injected array variables
# `printenv` and `env` lists injected array variables, as individual entries.

 

 

I've implemented workaround, which * may be integrated into the plugin * , that can be used to fix the main issue. It's available as a gist on github:


[https://gist.github.com/f-steff/1181f8f5907ae9da73779aba8182df3b#file-fixinjectedarraysinbash-sh]

Using this workaround, the output from my test injection above looks like this:
{code:java}
>. ./FixInjectedArraysInBash.sh
>echo ${test[0]}
string1
>echo ${test[1]}
string2
>echo ${foo}
bar{code}
h1. Second related problem.

A warning may be needed when this happens!

When importing/declaring variables like this:
{code:java}
test[0]=string1
test[1]=string2
test=string3
{code}
will result in an unintended overwriting of {{test[0]}}, resulting in an shell array variable declared like this: 
*
{{test=([0]="string3" [1]="string2")}}

 
 
Reply all
Reply to author
Forward
0 new messages