示例#1
0
        /// <summary>
        /// Gets the effective environment variables, taking into account default and machine-specific values
        /// </summary>
        public IBuildParameters GetEffectiveEnvironmentVariables(Process pip, PipFragmentRenderer pipFragmentRenderer, IReadOnlyList <string> globalUnsafePassthroughEnvironmentVariables = null)
        {
            Contract.Requires(pipFragmentRenderer != null);
            Contract.Requires(pip != null);
            Contract.Ensures(Contract.Result <IBuildParameters>() != null);

            var trackedEnv          = pip.EnvironmentVariables.Where(envVar => !envVar.IsPassThrough);
            var passThroughEnvNames = pip.EnvironmentVariables.Where(envVar => envVar.IsPassThrough).Select(envVar => pipFragmentRenderer.Render(envVar.Name));

            // Append any passthrough environment variables if they're specified
            passThroughEnvNames = globalUnsafePassthroughEnvironmentVariables != null?passThroughEnvNames.Union(globalUnsafePassthroughEnvironmentVariables) : passThroughEnvNames;

            IBuildParameters fullEnvironmentForPassThrough = MasterEnvironmentVariables != null?

                                                             // We first look at the env variables from the worker,
                                                             // then if the pass through variable is unset, we look at the env variables from the master.
                                                             // That's why, if MasterEnvironmentVariables is not null, it is overridden by the current environment variables.
                                                             GetFactory(ReportDuplicateVariable).PopulateFromDictionary(MasterEnvironmentVariables).Override(FullEnvironmentVariables.ToDictionary()) :
                                                                 FullEnvironmentVariables;

            return(m_baseEnvironmentVariables
                   .Override(trackedEnv.ToDictionary(
                                 envVar => pipFragmentRenderer.Render(envVar.Name),
                                 envVar => envVar.Value.ToString(pipFragmentRenderer)))
                   .Override(fullEnvironmentForPassThrough.Select(passThroughEnvNames).ToDictionary()));
        }
示例#2
0
        /// <summary>
        /// Gets the effective environment variables, taking into account default and machine-specific values
        /// </summary>
        public IBuildParameters GetEffectiveEnvironmentVariables(Process pip, PipFragmentRenderer pipFragmentRenderer, int currentUserRetryCount, IReadOnlyList <string> globalUnsafePassthroughEnvironmentVariables = null)
        {
            Contract.Requires(pipFragmentRenderer != null);
            Contract.Requires(pip != null);
            Contract.Requires(currentUserRetryCount >= 0);

            var trackedEnv          = pip.EnvironmentVariables.Where(envVar => !envVar.IsPassThrough);
            var passThroughEnvNames = pip.EnvironmentVariables.Where(envVar => envVar.IsPassThrough).Select(envVar => pipFragmentRenderer.Render(envVar.Name));

            // Append any passthrough environment variables if they're specified
            passThroughEnvNames = globalUnsafePassthroughEnvironmentVariables != null?passThroughEnvNames.Union(globalUnsafePassthroughEnvironmentVariables) : passThroughEnvNames;

            IBuildParameters fullEnvironmentForPassThrough = OrchestratorEnvironmentVariables != null?

                                                             // We first look at the env variables from the worker,
                                                             // then if the pass through variable is unset, we look at the env variables from the orchestrator.
                                                             // That's why, if OrchestratorEnvironmentVariables is not null, it is overridden by the current environment variables.
                                                             GetFactory(ReportDuplicateVariable).PopulateFromDictionary(OrchestratorEnvironmentVariables).Override(FullEnvironmentVariables.ToDictionary()) :
                                                                 FullEnvironmentVariables;

            IBuildParameters effectiveVariables = m_baseEnvironmentVariables
                                                  .Override(trackedEnv.ToDictionary(
                                                                envVar => pipFragmentRenderer.Render(envVar.Name),
                                                                envVar => envVar.Value.ToString(pipFragmentRenderer)))
                                                  .Override(fullEnvironmentForPassThrough.Select(passThroughEnvNames).ToDictionary());

            // If the variable to indicate the retry attempt is set, make sure it gets populated
            if (pip.RetryAttemptEnvironmentVariable.IsValid)
            {
                effectiveVariables = effectiveVariables.Override(
                    new[] { new KeyValuePair <string, string>(pipFragmentRenderer.Render(pip.RetryAttemptEnvironmentVariable), currentUserRetryCount.ToString()) });
            }

            return(effectiveVariables);
        }