windows batch命令" =="操作员奇怪的行为

时间:2016-07-19 15:34:19

标签: windows batch-file jenkins command-prompt

我在jenkins中有一个Windows批处理命令:

set /p Build=<version.txt
IF ("%Build%"=="%VERSION%") (echo version doesn't match)
IF NOT ("%Build%"=="%VERSION%") (echo version match) 

从构建中获取Build和VERSION。以上的输出是

w:\ce-billing-release>set /p Build= 0<version.txt 
w:\ce-billing-release>IF ("1.1.0" == "1.1.0") (echo version match ) 
w:\ce-billing-release>IF NOT ("1.1.0" == "1.1.0") (echo version doesn't match ) 
version doesn't match

即使它得到变量= 1.1.0的正确值,由于某种原因它认为它们不相等。我错过了什么?

1 个答案:

答案 0 :(得分:3)

请勿使用()来分隔比较。 () ifC:\Users\marc>IF ("1.1.0" equ "1.1.0") (echo version match ) C:\Users\marc>IF "1.1.0" equ "1.1.0" (echo version match ) version match 没有意义,并且会成为正在比较的字符串的一部分:

            //Retreive total hits and hits in last 30 days from google analytic

            //This is the API url which we're storing to a string
            string scope = AnalyticsService.Scopes.AnalyticsReadonly.GetStringValue();

            //For whatever reason, this is labelled wrong. It is the email address
            //that you have added as a user to your Analytics account
            string clientId = "*******@developer.gserviceaccount.com";

            //This is the physical path to the file we downloaded earlier
            //To demonstrate this, I've kept the full path to my key file.
            //Obviously, you will need to change this to match where you've
            //stored yours.
            string keyFile = @"C:\key\*******.p12";

            //The password Google gives you, probably the same as the one below
            string keyPassword = "notasecret";

            //Store the authentication description
            AuthorizationServerDescription desc = GoogleAuthenticationServer.Description;

            //Create a certificate object to use when authenticating
            X509Certificate2 key = new X509Certificate2(keyFile, keyPassword, X509KeyStorageFlags.Exportable);

            //Now, we will log in and authenticate, passing in the description
            //and key from above, then setting the accountId and scope
            AssertionFlowClient client = new AssertionFlowClient(desc, key)
            {
                ServiceAccountId = clientId,
                Scope = scope
            };

            //Finally, complete the authentication process
            //NOTE: This is the first change from the update above
            OAuth2Authenticator<AssertionFlowClient> auth =
                new OAuth2Authenticator<AssertionFlowClient>(client, AssertionFlowClient.GetState);

            //First, create a new service object
            //NOTE: this is the second change from the update
            //above. Thanks to James for pointing this out
            AnalyticsService gas = new AnalyticsService(new BaseClientService.Initializer() { Authenticator = auth });

            //Create our query
            //The Data.Ga.Get needs the parameters:
            //Analytics account id, starting with ga:
            //Start date in format YYYY-MM-DD
            //End date in format YYYY-MM-DD
            //A string specifying the metrics

            DataResource.GaResource.GetRequest r =
                gas.Data.Ga.Get(googleID, "2005-01-01", DateTime.Now.ToString("yyyy-MM-dd"), "ga:totalEvents");


            //Specify some addition query parameters
            r.Filters = "ga:eventCategory==appStart;ga:eventAction==user";

            //Execute and fetch the results of our query

            GaData d = r.Execute();