diff --git a/src/plugins/gres/gpu/gres_gpu.c b/src/plugins/gres/gpu/gres_gpu.c
index 31e1aa524418c79e0ee4227fd00b3dada1b47f09..b0b514697b050f6478194e5538ffc4bbaeeb34c6 100644
--- a/src/plugins/gres/gpu/gres_gpu.c
+++ b/src/plugins/gres/gpu/gres_gpu.c
@@ -109,7 +109,7 @@ const uint32_t	plugin_version		= 100;
 
 static char	gres_name[]		= "gpu";
 
-static int *gpu_devices;
+static int *gpu_devices = NULL;
 static int nb_available_files;
 
 /*
@@ -199,7 +199,10 @@ extern void job_set_env(char ***job_env_ptr, void *gres_ptr)
 				dev_list = xmalloc(128);
 			else
 				xstrcat(dev_list, ",");
-			xstrfmtcat(dev_list, "%d", i);
+			if (gpu_devices && (gpu_devices[i] >= 0))
+				xstrfmtcat(dev_list, "%d", gpu_devices[i]);
+			else
+				xstrfmtcat(dev_list, "%d", i);
 		}
 	}
 	if (dev_list) {
@@ -236,7 +239,10 @@ extern void step_set_env(char ***job_env_ptr, void *gres_ptr)
 				dev_list = xmalloc(128);
 			else
 				xstrcat(dev_list, ",");
-			xstrfmtcat(dev_list, "%d", i);
+			if (gpu_devices && (gpu_devices[i] >= 0))
+				xstrfmtcat(dev_list, "%d", gpu_devices[i]);
+			else
+				xstrfmtcat(dev_list, "%d", i);
 		}
 	}
 	if (dev_list) {