예제 #1
0
        public void JenkinsTakesLocalBranchNameNotRemoteName()
        {
            // Save original values so they can be restored
            var branchOrig      = environment.GetEnvironmentVariable(branch);
            var localBranchOrig = environment.GetEnvironmentVariable(localBranch);

            // Set GIT_BRANCH for testing
            environment.SetEnvironmentVariable(branch, "origin/master");

            // Test Jenkins that GetCurrentBranch falls back to GIT_BRANCH if GIT_LOCAL_BRANCH undefined
            buildServer.GetCurrentBranch(true).ShouldBe("origin/master");

            // Set GIT_LOCAL_BRANCH
            environment.SetEnvironmentVariable(localBranch, "master");

            // Test Jenkins GetCurrentBranch method now returns GIT_LOCAL_BRANCH
            buildServer.GetCurrentBranch(true).ShouldBe("master");

            // Restore environment variables
            environment.SetEnvironmentVariable(branch, branchOrig);
            environment.SetEnvironmentVariable(localBranch, localBranchOrig);
        }
    public void JenkinsTakesBranchNameInPipelineAsCode()
    {
        // Save original values so they can be restored
        string branchOrig         = Environment.GetEnvironmentVariable(branch);
        string localBranchOrig    = Environment.GetEnvironmentVariable(localBranch);
        string pipelineBranchOrig = Environment.GetEnvironmentVariable(pipelineBranch);

        // Set BRANCH_NAME in pipeline mode
        Environment.SetEnvironmentVariable(pipelineBranch, "master");
        // When Jenkins uses a Pipeline, GIT_BRANCH and GIT_LOCAL_BRANCH are not set:
        Environment.SetEnvironmentVariable(branch, null);
        Environment.SetEnvironmentVariable(localBranch, null);

        // Test Jenkins GetCurrentBranch method now returns BRANCH_NAME
        var j = new Jenkins();

        j.GetCurrentBranch(true).ShouldBe("master");

        // Restore environment variables
        Environment.SetEnvironmentVariable(branch, branchOrig);
        Environment.SetEnvironmentVariable(localBranch, localBranchOrig);
        Environment.SetEnvironmentVariable(pipelineBranch, pipelineBranchOrig);
    }