diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp
index 250c1360a85ea9a7b71c7ab5f8ce9ea7776b6fc5..3de34a204764df8519e080392c80ebfc722abd5e 100644
--- a/src/plugins/projectexplorer/projectexplorer.cpp
+++ b/src/plugins/projectexplorer/projectexplorer.cpp
@@ -1797,6 +1797,7 @@ int ProjectExplorerPlugin::queue(QList<Project *> projects, QStringList stepIds)
         return -1;
 
     QList<BuildStepList *> stepLists;
+    QStringList names;
     foreach (const QString id, stepIds) {
         foreach (Project *pro, projects) {
             if (!pro || !pro->activeTarget())
@@ -1811,16 +1812,13 @@ int ProjectExplorerPlugin::queue(QList<Project *> projects, QStringList stepIds)
             if (!bsl || bsl->isEmpty())
                 continue;
             stepLists << bsl;
+            names << displayNameForStepId(id);
         }
     }
 
     if (stepLists.isEmpty())
         return 0;
 
-    QStringList names;
-    foreach (const QString &stepId, stepIds)
-        names << displayNameForStepId(stepId);
-
     if (!d->m_buildManager->buildLists(stepLists, names))
         return -1;
     return stepLists.count();